7 kyu
Fizz Buzz
2,171 of 26,360stephenyu
Loading description...
Algorithms
Fundamentals
Arrays
View
Career Accelerator
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 kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/226.
Please join the discussion to help us identify duplicate kata and retire them.
This kata was decided to stay.
Description should be language-agnostic
i
fizz buzzmaked Translation DartNo random tests in Haskell
python new test framework is required. updated in this fork
Approved
This comment has been hidden.
You're making a function that will be called a number of times. All your code should (in 99% of cases) be contained inside this function. Any global variables retain state between calls.
Hello everyone,
New to CodeWars and relatively new to (python) programming. I think the site has huge potential to help people like me with their programming skills, however, I seem to have stumbled at the first hurdle. I tried to use a very simple "input()" command and when I press the test button to test I get an end of line error. When I run the same code in another python editor, external to CodeWars, the command works and no error is produced. Any advice please? It feels that this may be something fundamentaly wrong with the way I am using the site and its resources. The code I tried to run was: number = input('Enter your number:'), many thanks!
You shouldn't use input on Codewars in general. A number will be fed to your function in the tests. Just assume that function will receive the necessary parameters to execute without having the user entering any kind of number. Hope this helps! If you reset your solution, you should use "n" as the number who will be necessary to code your solution.
Many thanks!!!
Scala translation with upgrade to 3.0
.
My JS solution is passing the preliminary tests for 10 numbers, one number, and one random 1-100 integer, but for the 30 and 100 numbers tests that run when I try to attempt the kata it's returning a fail. Here's the error code for 30, and it's the same with 100 - i.e., it looks like the expected and actual results are identical! Am I missing something simple here?
Thanks in advance! (edited to try and get the actual and expected arrays to align so they can be more easily compared...)
Fails with 30 numbers!: expected
'[1,2,"Fizz",4,"Buzz","Fizz",7,8,"Fizz","Buzz",11,"Fizz",13,14,"Fizzbuzz",16,17,"Fizz",19,"Buzz","Fizz",22,23,"Fizz","Buzz",26,"Fizz",28,29,"Fizzbuzz"]' to equal '[1,2,"Fizz",4,"Buzz","Fizz",7,8,"Fizz","Buzz",11,"Fizz",13,14,"FizzBuzz",16,17,"Fizz",19,"Buzz","Fizz",22,23,"Fizz","Buzz",26,"Fizz",28,29,"FizzBuzz"]'
They are not identical.
Oh damn 💀
This comment has been hidden.
You just print the value.
You should return it.
This comment has been hidden.
you should post your code here to get help, marking it as having spoiler content
This comment has been hidden.
not
"Fizzbuzz"
but"FizzBuzz"
b
=>B
Test throws a systems error with test.js when using javascript to solve kata. /home/codewarrior/node/test.js:49 }); ^
SyntaxError: Unexpected token ) at new Script (vm.js:80:7) at createScript (vm.js:274:10) at Object.runInThisContext (vm.js:326:10) at Module._compile (internal/modules/cjs/loader.js:664:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at /home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/lib/mocha.js:250:27 at Array.forEach () at Mocha.loadFiles (/home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/lib/mocha.js:247:14) at Mocha.run (/home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/lib/mocha.js:576:10) at Object. (/home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/bin/_mocha:637:18) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Check your code. It seems you have one
}
missing.Wow I'm an idiot, thank you so much for the help lol :)
This comment has been hidden.
It should be 'FizzBuzz' (notice capital letters)
This comment has been hidden.
Upgraded to JUnit 5, used paramterized tests, added more random tests and approved.
Powered by katafix 🤖
This comment has been hidden.
Haven't tested, but looking at it, I think you would replace a number like 15 with 'Fizz', and the next clause would fail to find it.
oh wow, yeah i get what you mean, that might actually be the case, thank you.
Scala Translation submitted. Please share your thoughts!
Approved
This comment has been hidden.
Same problem I had, it has to be 'FizzBuzz' not 'Fizzbuzz'.
What SipofTea said! It is case sensitive.
This kata has varying output types (as well as function names) between the translations, and as such, currently the dynamic language descriptions are lacking, unclear, or misleading.
Fixed. Please reply if I missed something.
This comment has been hidden.
This kata has 9 language translations, yet only two dynamic language examples in the description. Therefor, being that the
csharp
example is before theprolog
example, AFAIK all languages other than prolog default to the C# example. Yet, that language expects a different type of output, namely an array of strictly strings, than (most?) other languages, which expect a mixed-type array as a return value.Should be better now.
not fu*king clear!!!
Well, I think I'm ready for the interview now 🧠
When use map method the test shows this error: n.map is not a function
Are you using .map on number? Only arrays have .map method.
i am using on array
If it was array, there would be no error. Try using
console.log()
before to see what it really is.Thanks, i should create an array first, but not asume that input will be an array.
Yep, input was just a number. You can see it on bottom right window, it shows what kind of tests there are.
This comment has been hidden.
There's no closing parathesis for the last second line.
Also next time you post your code, use proper formatting so that the indentation is preserved or else no one will care to read your code!
Thank you!
silly stuff- check all the words "then" in the description of the exercise, it should probably be "than"
.
Prolog translation kumited. (author is inactive)
In Python there is only one random test. (Although there is one test from 1 - 100)
Should more be added?
Sounds more like an issue. In a way, it's already raised below. It seems pretty much impossible to combat 'cheating' for this one. You could increase
n
, but it won't fix the underlying problem.fixed by latest fork
Java translation Kumited! please accept :smile:
Approved the fork of the fork.
This comment has been hidden.
Bravo! Also, you declare a variable in Elixir much like in other languages, something = "whatever", except as you've noticed sometimes declaring a variable is very optional, and also there is a caveat: the = is also a pattern-matching operation, more akin to a mathematical = sign, which can be very fun to use, or very ""fun"" if you don't know what you're doing. e.g. x = 1 1 = x # true 2 = x # false Note that if we want to pattern-match two variables, we will have to use ^ on the left-hand side to "pin" it or it will be rebound to the right-hand side.
This comment has been hidden.
This comment has been hidden.
Isn't 100 enough to dicsourage from doing it manually and how can anyone do that without writing a solution?
This comment has been hidden.
Duplicate issue.Oops, didn't notice the language is different in your comments. Nonetheless, it doesn't seem like an issue, and is pretty much impossible to fix given you can hardcode the sequence to any number you want, and return the very same slices of it.
not duplicated since it's coffescript and not javascript
This comment has been hidden.
Broken in python. Disappointing.
Why do you say that? It worked for me.
I'll paste one of the failed random test results:
Should fizzify 30 numbers correctly Fails with 30 numbers!: [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'Fizzbuzz', 16, 17, 'Fizz', 19, 'Buzz', 'Fizz', 22, 23, 'Fizz', 'Buzz', 26, 'Fizz', 28, 29, 'Fizzbuzz'] should equal [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16, 17, 'Fizz', 19, 'Buzz', 'Fizz', 22, 23, 'Fizz', 'Buzz', 26, 'Fizz', 28, 29, 'FizzBuzz']
But on inspection, it does equal what it "should equal".
Are you sure they're the same?
Oh wow yeah you're right... my bad...
In that case, my only suggestion is there should be a sample test for a case with n >= 15 to catch at least one 'FizzBuzz'
Kotlin translation is ready!
https://www.codewars.com/kumite/5c6d75f1d2c6492845df7509?sel=5c6d75f1d2c6492845df7509
It could use random tests in all languages.
Isn't that more of an issue? Other than @Javatlacati already reported it :point_up:
Well, the kata is old, so I considered it a suggestion at that time, in new katas should be an issue for sure. Let's close this and leave the issues then.
Saw the complaints that it wasnt working so tried it. The Python version was fine. Good Kata.
Ruby: test cases use
Test.expect
instead ofTest.assert_equals
. Sample tests are up to date, though.Ruby: getting errors when test argument is multiple of 10 (i.e. 30 or 100) or 1, even though output is correct (output is 'buzz' and '1' but error says 'Fails: 10' etc and 'Fails: 1'). Any ideas as to why? Is this just a bug or am I doing something wrong? Any way to fix this to trick the bug?
It's
'Buzz'
not'buzz'
could it be that? Also you have to return numbers not strings (apart of where you should return strings). AFAIK there is no bug in the tests, I've solved it with no problem.Everything is working correctly. There must be a mistake in your code.
Thanks. Yes I should have been more clear. I did use "Buzz" and numbers not strings. I'll just have to take another look at my code. It is working in terminal irb and sublime text and I have shown it to other devs who have said it's correct. So I'm a lil lost tbh. I'll keep at it. But thanks for your help.
Nope, definitely not just my code. To try to check if there is a bug I found a heap of other peoples solutions and tested all of them. They all came up with the exact same error. I tried code very different from mine so it really shouldn't have come up with the same error (fails: 10 and multiples of 10). What brower are you using? I tried in Chrome and Firefox. If your code is working maybe it has to do with that? Just clutching at straws. I'm also finding that if I "reset" the solution it doesn't really wipe it. It clears it but if I then refresh the page my old code shows up again in the window. My code automatically shows up in the Codewars solution window when I google and open "Codewars Fizz Buzz" in other browers too. Maybe it's somehow stuck in a loop of an old error or something? I dunno, I'm pretty new to this whole game. Any any suggestions would be most appreciated. Thanks.
Paste your code using proper markdown and mark your post as having spoiler content.
I just did it in ruby, there is effectively an issue, but emmaalbury's code is effectively wrong too.
@emmaalbury:
The issue now: the test cases use
Test.expect
so the warrior has no idea about what the problem is.This comment has been hidden.
An array of values, not one value.
DUUUUUUUUUUUUH! Ha ha, oh dear. I changed it and it passed straight away. I'd been working on multiple versions of Fizzbizz and overlooked that requirement in this one. That was dumb of me. I'll delete this thread as I shouldn't hog space if it's not going to help anyone. Thanks for your help!
You can't delete a post after it has replies, at least now you know about proper markdown and spoiler flag ;)
lovely kata! thanks.
Ugh, publish timeout.
Let's try this again.
Fixed for real.
Kata (kinda) fixed since site change made at https://github.com/Codewars/codewars.com/issues/1010
Since 500 solves has already been made I can't change the test cases. This is the best I can do. :(
At least it's solvable (normally) now.
This comment has been hidden.
I actually haven't had an issue with the ReferenceError. However, I am having an issue passing the 30 numbers test case EVEN THOUGH my output is exactly the same as what is expected by the test case (Python 3.4) which makes no sense to me. Has anyone else run into a similar issue?
TestCases are still broken, ReferenceError: fizzify is not defined message appears
Figured this out for myself when I saw the error message, but yes, this should definitely be fixed in the test cases!
This error should have been fixed. As others have stated, just put fizzify = fizzbuzz globally.
(Kinda) fixed
Still broken. Be sure to put fizzify = fizzbuzz; globally, in your solution.
(Kinda) fixed
Great solution, fizzify is function doing the same what fizzbuzz do
Testcase still not fixed ...
(Kinda) fixed
Hey Guys!
I am getting this:
Fizzbuzz Should fizzify 10 numbers correctly Fails with 10 numbers! - Expected: [1,2,"Fizz",4,"Buzz","Fizz",7,8,"Fizz","Buzz"], instead got: [1,2,3,4,5,6,7,8,9,10] 0 Passed 1 Failed 0 Errors Process took 202ms to complete
I got my array setup in the function and the .push under each if statement but It just prints 1-10.
any help?
you need to push the words
Fizz
andBuzz
into the array at the correct points.I actually noticed my dumb mistake haha - I had my if statment setup with if i & 5 === 0 instead of if i % 5 === 0 haha i was just using the wrong symbol :/
The JavaScript test cases are broken. The line
arr.push(fizzify(i));
should bearr.push(fizzbuzz(i));
.To workaround, put
var fizzify = fizzbuzz;
in your solution.This worked out for me. It seems the author never fixed the bug. Thanks Paul.
Cheers Paul. Yes it still isn't fixed.
And just to clarify if your putting the workaround inside the function remove the 'var' part so that it is a global variable or it doesn't work.
Thanks for the tip Paul! Your solution worked for me as well.
Thx! This worked for my solution.
(Kinda) fixed
This comment has been hidden.
What even is
length
and why do you changen
?..I was getting this error:
and I could not fiure out the answer. I even ended up deleteing my visible code test. (oops!) I still did not find a way to reset or bring back the original test code. BUT I did figure out that seeing the test code does not matter to the testing conditions.
To any coders who are in the same spot. You can still solve this problem: The hint is
fizzify is not defined
and you can enter this code in the solution window not the test case window.I was getting this error too....
Same here, had to switch to Ruby to complete the Kata :(
Looks fixed.
fizzify!
This comment has been hidden.
(Kinda) fixed
While submission decision appears error: ReferenceError: fizzify is not defined at fizzbuzzRandom at Test.it at Test.describe
Does anyone know what is it?
It's a bug in the test code. If you want a challenge, read the error carefully. It gives you information needed to pass the kata's bug.
C# version kumited some more test cases, but no random test case also I added a rule (for now only for C#) for inputs smaller 1
Great kata to practice using the range function!
now see if you can manipulate the array sans loops :)
This comment has been hidden.
Essentially, the last test case is testing a different function than the first 4 test cases.
I would recommend changing test case 5 to test the same function that test cases 1 - 4 test. (FizzBuzz)
This comment has been hidden.
This is my code at the end of my program but it tells me "Unexpected token at 'else{' " and if i remove the semi-colon, it says "Unexpected token '(' at '});{});' "! What is the problem!
if (stuff){ stuff here; }; else{ stuff here; }; return spoiler;
This comment has been hidden.
(Kinda) fixed
Like a few others, I had resorted to a hack to pass the last test thinking it was a bug in the tests.
But now that I've seen some of the solutions & had a think about it, I realised why that last test is testing for a 'fizzify' function. Good test! But it probably should be made clearer in the Kata's description that a second function with that name should be part of the solution instead of only finding out after the first submission attempt.
(Kinda) fixed
I found the same error in the test cases:
"Should fizzify a random positive integer (1~100) correctly ReferenceError: fizzify is not defined at fizzbuzzRandom at Test.it at Test.describe
Me two. Do you know how can i solve it?
There's an error with the last test case in this Kata. The last test case is looking for a function called "fizzify", but it doesn't exist and the instructions do not say anything about creating another function called fizzify. Here's the error:
Should fizzify a random positive integer (1~100) correctly ReferenceError: fizzify is not defined at fizzbuzzRandom at Test.it at Test.describe
at Object.
This comment has been hidden.
Only iterables can be appended to a
list
with+=
.The last test passes to me if I put:
var fizzify=fizzbuzz;
Yet still annoying and I hope it is fixed soon.
Cheers :)
hi, am kind of new here, am trying to solve this Fizzbuzz in python. I managed to solve it on my computer correclty but on here i get the following error :
Traceback: in in fizzbuzz TypeError: not all arguments converted during string formatting
0 Passed 0 Failed 0 Errors
--> is there a problem or anything i should know or is it just my solution that's incorrect? any help would appreciated
Hi! It's probably an issue with a string formatting you're using. I tend to avoid them, but there's a use case for everything. This post might be helpful: http://stackoverflow.com/questions/18053500/typeerror-not-all-arguments-converted-during-string-formatting-python
If not, you can always post a code snippet marked as a spoiler and then people who have finished can take a look and possibly help advise. Also, check that the versions of python match up. I'm pretty sure Codewars is running 2.7.3. Cheers!
Try using this test case:
In addition to the
fizzify
not defined bug, the random number test is broken. It callsfizzbuzzRandom
twice and compares the results and of course the results are identical so it'll always succeed (as long asfizzbuzzRandom
wouldn't crash). It should call it once and compare that result to the array returned byfizzbuzz
.As a result,
fizzify
can be defined to return anything, as long as isn't random and depends purely on the value of its argument. It's actually supposed to return only a single value -"Fizz"
,"Buzz"
,"FizzBuzz"
, or the number it was called with - not an array, so it's not the same asfizzbuzz
. I.e.etc.
(Kinda) fixed
The "fizzyif" test cases is very misleading. It should either be removed or description for the same added in the problem statement.
stephenyu, could you please fix this kata for JS. Pavel has already pointed out the bug
(Kinda) fixed
This comment has been hidden.
This comment has been hidden.
(Kinda) fixed
Gives me this on the last test, when submitting my solution.
ReferenceError: fizzify is not defined at fizzbuzzRandom at Test.it at Test.describe
Pavel, this is my fault. I've translated this kata to JS, but just can't find the edit button to fix this, I'M SORRY!
I have the same error.
Cauli, please fix this error
Sorry, it is a bug. I've translated this Kata, it is orphaned by the author, and I don't have the permission to fix it. Sorry guys.
Same error. sad
cauli: Could you write to the administrator with this situation?
This comment has been hidden.
You should have message to explain the error in your test, i can't understand why my code is failing.
The description says that N will never be less than 0, but doesn't say how the case n==0 should be handled. If you want fizzbuzz(0) === [], you should make that clear in the description and add a test case for that, otherwise change the description to say N will never be less than 1.
Yeah you are right, I meant "Less Than 1". I'll make this change.