6 kyu
Jungerstein's Math Training Room: 1. How many zeros are at the end of n!! ?
990 of 1,508jungerstein
Loading description...
Puzzles
Mathematics
Number Theory
Discrete Mathematics
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
I don't know if your code is correct, but you must find a way to do the calculation without computing
n!!
, because this is a very expensive operation; moreover in some languages (like JS) ordinary numbers cannot hold such huge values (which may be the reason of your code failure).c++ translation???
No odd inputs in examples? lol 😆 How come?
guys what is !! in n!! from what i know its not or n notnot ? im confused im new ^_^
The definition is in the description. It's similar to factorial of n or n! but with that definition depending of n being even or odd.
It's not related to logical not operator at all.
It's written in the description?
5!!
is1 * 3 * 5
, and6!!
is2 * 4 * 6
. The exclamation marks here are not a part of any programming language, but a part of some agreed upon notation.copy thanks!!
Hi ! is Factorial
OKAY THANKS!! <3
Fork for C which fixes the following warning:
Approved :)
Python fork
count_zeros_n_double_fact(30)
) to be more language agnosticApproved!
My numbers are reaching infinity. Am I approaching the problem incorrectly?
Yes.
After passing the basic tests, I've got this message: "For the random test with 4387: should be 0, but you got 550". Why the output should be zero in that case? It doesn't make sense to me, since the input 4387 is large enough to contain many zeros in 4387!!.
The expected answer is fine. That number has no zeros at the end.
You're absolutely right. Now, I've got it. Thanks.
This comment has been hidden.
I cant see enough test case answers to debug my solution
Can't to approve due to a conflict in the description. Forks with the correct description for COBOL and Go.
Both approved, thanks.
I don't understand the prompt. How does 384 have no 0s but 30 has 3 0s..
30!!
has 3 zeroes.C# Translation
This comment has been hidden.
for python n = 41, why output should == 62?
that's not an issue, that's a question. Issues or for disfunctionning katas.
(and I don't have the answer, sorry)
There's no such a test. You probably misinterpreted the failure message.
but for all odd number, no 0 at the end, why solution requires sol > 0?
Test Results: Please pass examples in kata description Test Passed Test Passed Tests with larger number Test Passed 41 should equal 62
41 is the result you've returned. That is what
41 should be 62
means.If you want to see the input, you need to print it out yourself.
I see, thank you :)
The tests in the C version do not show the expected outcome, whereas the tests in the Python version do. That makes the C version harder to solve, as no hints are given into towards the right answer. Please adapt
Sorry for the inconvenience for all the C trainees.
I have fixed it according to your suggestion by adding an extra piece of information.
Since
cr_assert
does not acceptchar[]
as argument (only string literal), it takes me some time to fix the tests up.I'm not sure the C version is working correctly, as my output is:
Log n = 8 number of 0 = 0 Test Passed
Log n = 30 number of 0 = 3 Test Passed
Log n = 1443 number of 0 = 144 Test Passed
Log n = 9295 number of 0 = 929 Test Passed
Log n = 302 number of 0 = 30 The expression count_zeros_n_double_fact(randomed) == test_zeros(randomed) is false.
This comment has been hidden.
Problem is with user code, not the kata, then. Closing.
In JS, the large number tests are making it impossible to solve, I think. For numbers like 589 they get so large that the product is just (1312312313xE^24) or something like that and it can't be parsed.
If you would like to count something, you will not always need to generate the full result first.
A viable suggestion for solvers might be try to work out n = 1, 2, 3, 4 to something like 15 (not too big), and guess the pattern / try to find out what is really affecting the solution.
JS can only handle number less than 10 ^ 16 before switching to exponentiation form. You have two options:
hello there. enjoyed chipping away at your kata. i am running into some trouble with the exponential...im still a newb, but i did put in some time... any tips?
Hello.
If you meet an exponential form, you might have chosen the brute-force solution: (1) generate the full answer, (2) then use some ways to check the digits at the end, (3) then judge whether they are zero, (4) then add your counter if there is another zero.
However, there are some other ways to count them, especially when there are some patterns.
Another possible way (I think I can expose that the n in test cases are not that formidably large) is to handle the multiplication (to say, when the product > 10000000) yourself. You will need a list or an array to do that: if you use a list of integers (just name it as l), you can use l[0] for the highest (or lowest) digits, and operate as you were in classrooms of arithmetic. You can make your coding easier by have one digit per element, or use different base (e.g. 1000, 1000000, or 65536 or something alike).
Too bad, I was expecting
n!! == (n!)!
:/Too bad, but I am sorry that it seems not the common way of defining n!!. :-)
Also it is wonderful to inspire some methods for such huge numbers.
When I discovered this kata, I just read the title, then I began to work on an algorithm based on my assumption. After quite a struggle, I opened the editor and saw the full description: well wrong algorithm, but it was easy to adapt it. Thanks for the challenge anyway! :')
Hello,
jungerstein
I've added a JavaScript translation.Thank you for your translation.
The arguments of
assert_equals
are in the wrong order.Thanks for your reporting. The wrong orders have been swapped in both example tests and final test.s