Welcome to the Coding Challenge.
Here I will post a coding challenge every few days that you can solve. There will be easy ones and hard ones, pretty mixed.
How does it work?
- Try to solve the challenge in whatever language you find fitting
- You can use a new language you always wanted to learn or show off your golfing skills
- Post a comment containing your code (in
```code here```
) and some info on how the code works or what is remarkable - Optional: Create a post with the tag #coding-solution
- In that post walk other users through the process of solving your challenge. That way they can learn and try it out on the next one
- Optional: Read and review other peoples code, try to find bugs, give feedback and learn
Why even bother?
- Training is everything, the more you train your mind to think in code, the better you are prepared
- You may learn a few new tricks from reading other solutions
- I will send tips for really good solutions (and use the liquid rewards of this post for it too)
- You may get recruited if someone likes your code (f.e. I am looking for talents)
Challenge #1 – FizzBuzz
This challenge is a pretty basic one, but the devil lies in the detail.
Implement a fizzbuzz
function taking an integer n
that abides to these specifications:
- if
n
is a multiple of 3, printFizz
- if
n
is a multiple of 5, printBuzz
- if
n
is a multiple of 3 and a multiple of 5, printFizzBuzz
- in all other cases print the number
Also create a snippet or main function that calls fizzbuzz
for all values from 0 to 100, ascending.
Remarks:
- If you use a pure functional language, try returning a string instead of using a print Monad (both are allowed)
- Bonus points for:
- handling edge cases
- good coding practices and modularity
- useful and meaningful tests
- beautiful (readable, self-documenting) code
Please keep the #coding-challenge tag clean of solutions.
Two solutions with Haskell: http://codepad.org/tIR16emr
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for your submission! I really hoped that I get a Haskell one 🐑
Your first solution is pretty concise, not much to say there. The second one is really cool! Abstracting it as rules is smart and that filter reduces logic duplication.
I think you can make this a bit more readable with making rules a constant and extracting the tester in a helper function that has a good name.
Looking forward to you writing a post on how your process was, implementing the second version of it.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Only comment I have is the question asked for 0 to 100 but the solutions are for 1..100. How does either solution work for 0? Dealing with 0 shouldn't be too difficult, though 0/x is going to be 0 and 0 mod x is also 0. I guess it will/should print FizzBuzz for n=0.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
True his solution starts at 1, good catch, here is a tip! But yeah it will work with 0, pretty sure.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @ratticus! You have just received a 0.5 SBD tip from @reggaemuffin!
@tipU quick guide | How to check your pending payouts.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Check this one: http://codepad.org/GPTa3Tgm
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I don't know what you mean by
It's already a constant there.
Since the filter phrase used once and it's a short one, I'd argue it's easier to read it this way.
I implemented/borrowed the second one because I wanted to have a generic solution that is easy to expand or change with new
rules
. Now, all you need is to update therules
to get a newFizzBuzz
.Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Ooh, this is right up my alley! I'll start out with JavaScript (because I already know it) but I might switch to different languages for future challenges just for the fun of it. I'll be looking forward to these!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Looking forward to your solution :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
My Solution in plain old JS5 :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Looks good to me ;)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Wow, Really wish I could code lol, I have tried a couple of times to learn but just not making considerable progress. I have found a niche in data analysis I am so passionate about though , I need some coding ability to succeed in this area like R,Python and SQL. Perhaps this would pave a way for me into "core coding" :). Would closely follow this and see what I can learn. Great initiative
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I suggest you check out the solutions then and learn from it :) That is what this challenge is about, you can see how it can be done and learn to think that way, till you can do it yourself
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Yeah I got my pen and notebook ready. Would try to understand the thought process of each solution.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I suggest you don't hijack other posts and ask for upvotes.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
My solution for python:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
One suggestion I would have is keep the return type of fizzbuzz consistent. So I would probably do a
return str(n)
to ensure it is always a string. And in python I would follow snake_case with my variables somultiple_of_3
would be the preferred format.Your solution looks good and I think it it correct, well done :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
lol, snake case for python. I get it! =D
I kinda wonder about these traditions of code styles and methods. It would be cool to tell a story about the history of traditions like "hello world" and such.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for the feedback. I'm come from Java. Automatically coded in it's coding style. lols
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You're on the right track.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Brilliant!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I'm gone do it.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice! Post your solution here when you got it. https://repl.it is really good for sharing code.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
My ruby solution to FizzBuzz: https://repl.it/KNug/2
I used the range iterator
(0..100).each
because it is really nice to read in my opinion.Constants are important, but
FIZZBUZZ
depends onFIZZ
andBUZZ
so a dynamic constant is best there.helper functions to test for the various cases are really helpful for testing at. And the final fizzbuzz function reads like natural language.
The code works for negative values just fine and all functions are pure, so it can be used without printing anything.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I've contemplating to make a career change and start coding, as my brother does ruby on rails and he could accelerate my progress.
Anyone has done this? Are you happy with your shift?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Coding is awesome, try it :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@reggaemuffin I want to know how young to learn kede easily, please teach me and please give me easy tips for me to learn it. I am very interested in your current posting of friends.
saya pingin tau bagaimana cara yang muda untuk mempelajari kede itu dengan mudah, tolong ajarin saya dan tolong beri saya tips yang mudah untuk saya mempelajari nya.saya sangat tertarik dengan postingan anda saat ini teman.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi, a quick example in clojure
Output:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
lisp! What a brilliant, old and unique language :) Hope to find free time and learn it well one day :P
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
:P true. You will, i'm sure about that
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
i like this. this i something i would do. not right now but soon. coding is fun and this would help me get better at it
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I wish I could understand those lines >.>
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I like it! I am not good at coding but I love the challenge and one sweet day win one of your challenges :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Next post Please. My mind is moving.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Can you give me feedback? Was it too hard or too easy? What would you like to see next?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for the information .. i am happy to see this news .. help devoted me
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Reading the comments gave me hope i can restart the basics of computer programming i learnt in undergraduates. I will follow the solutions and one day soon i will write my code.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great post and very interesting. Provide a very useful knowledge. Thank you so much for sharing
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great post and very interesting
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Holy crp this is so cool, i hope you can start a steemit computer science school to teach software development and basic coding to people, so they can kno enough to make thir ow bots and add fatures and plugins for steemit, i am interested in creating steemit chrome extensions for example. Thank u for this nd im mentyioning u inmy latest post :) about ur commenton how steempower has alot of social value that does equate to dollar value
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you 😊
I'll see about making these challenges steem specific, that could be fun 😊
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Cool concept, don't know how to code like that but still seems pretty dope
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You can always try it :) Or read the solutions others submit and see how they did it
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Interesting challenge. All I know is WordPress, but I'm open to studying the morbid stuff that you do here on Steemit like having a bot and stuff. I'm amazed with your skills. :-)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Wonderful post @reggaemuffin
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Probably the shortest FizzBuzz code
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You can go even shorter ;) But I mean the idea is to have it nice and readable and thought through :P
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Not the best looking code, however you could add some comments... :D
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
If I could code I would be all over this :) looks like a cool idea good luck!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You did not upvote me, please don't spam :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit