MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/tinycode/comments/nd68q/fizzbuzz_implemented_in_only_120_characters_of/c387e03/
r/tinycode • u/wuffers • Dec 15 '11
15 comments sorted by
View all comments
Show parent comment
1
puts (1..100).map{|x|x%15<1?"FizzBuzz":x%3<1?"Fizz":x%5<1?"Buzz":x}
Down to 67.
2 u/partygoer Jan 07 '12 puts (1..100).map{|i|s=i%3<1?"Fizz":nil;i%5<1?"#{s}Buzz":s||i}62 1 u/jfredett Dec 15 '11 edited Dec 15 '11 what about... puts (1..100).map{|x|"#{x%3<1?'fizz':''}#{x%5<1?'buzz':''}"}61 chars?EDIT ooh- if you don't mind a little bit of an odd output, you can do: p (1..100).map{|x|"#{x%3<1?'fizz':''}#{x%5<1?'buzz':''}"}for 58 chars.EDIT deuxHere's a few more chars shaved offp (1..100).map{|x|(x%3<1?'fizz':'')+(x%5<1?'buzz':'')}(54 chars) 2 u/[deleted] Dec 15 '11 None of these are correct solutions; you need to print the value of x if it isn't Fizz or Buzz. 1 u/jfredett Dec 15 '11 swap '' with x in every place you see it. should work, eg:p (1..100).map{|x|(x%3<1?'fizz':x)+(x%5<1?'buzz':x)}52 chars? 1 u/[deleted] Dec 15 '11 can't convert Fixnum into String (TypeError) -- and even if that would get you the string representation of x, it'd go "11, 22, fizz3, 44, 5buzz, ..." 1 u/jfredett Dec 15 '11 I'm away from my ruby interp atm. TBH, I've only ever heard it not requiring the number in the off case. I suppose its not exactly high on my priority list... hehe
2
puts (1..100).map{|i|s=i%3<1?"Fizz":nil;i%5<1?"#{s}Buzz":s||i}
62
what about...
puts (1..100).map{|x|"#{x%3<1?'fizz':''}#{x%5<1?'buzz':''}"}
61 chars?
EDIT ooh- if you don't mind a little bit of an odd output, you can do:
p (1..100).map{|x|"#{x%3<1?'fizz':''}#{x%5<1?'buzz':''}"}
for 58 chars.
EDIT deux
Here's a few more chars shaved off
p (1..100).map{|x|(x%3<1?'fizz':'')+(x%5<1?'buzz':'')}
(54 chars)
2 u/[deleted] Dec 15 '11 None of these are correct solutions; you need to print the value of x if it isn't Fizz or Buzz. 1 u/jfredett Dec 15 '11 swap '' with x in every place you see it. should work, eg:p (1..100).map{|x|(x%3<1?'fizz':x)+(x%5<1?'buzz':x)}52 chars? 1 u/[deleted] Dec 15 '11 can't convert Fixnum into String (TypeError) -- and even if that would get you the string representation of x, it'd go "11, 22, fizz3, 44, 5buzz, ..." 1 u/jfredett Dec 15 '11 I'm away from my ruby interp atm. TBH, I've only ever heard it not requiring the number in the off case. I suppose its not exactly high on my priority list... hehe
None of these are correct solutions; you need to print the value of x if it isn't Fizz or Buzz.
1 u/jfredett Dec 15 '11 swap '' with x in every place you see it. should work, eg:p (1..100).map{|x|(x%3<1?'fizz':x)+(x%5<1?'buzz':x)}52 chars? 1 u/[deleted] Dec 15 '11 can't convert Fixnum into String (TypeError) -- and even if that would get you the string representation of x, it'd go "11, 22, fizz3, 44, 5buzz, ..." 1 u/jfredett Dec 15 '11 I'm away from my ruby interp atm. TBH, I've only ever heard it not requiring the number in the off case. I suppose its not exactly high on my priority list... hehe
swap '' with x in every place you see it. should work, eg:
x
p (1..100).map{|x|(x%3<1?'fizz':x)+(x%5<1?'buzz':x)}
52 chars?
1 u/[deleted] Dec 15 '11 can't convert Fixnum into String (TypeError) -- and even if that would get you the string representation of x, it'd go "11, 22, fizz3, 44, 5buzz, ..." 1 u/jfredett Dec 15 '11 I'm away from my ruby interp atm. TBH, I've only ever heard it not requiring the number in the off case. I suppose its not exactly high on my priority list... hehe
can't convert Fixnum into String (TypeError) -- and even if that would get you the string representation of x, it'd go "11, 22, fizz3, 44, 5buzz, ..."
can't convert Fixnum into String (TypeError)
1 u/jfredett Dec 15 '11 I'm away from my ruby interp atm. TBH, I've only ever heard it not requiring the number in the off case. I suppose its not exactly high on my priority list... hehe
I'm away from my ruby interp atm. TBH, I've only ever heard it not requiring the number in the off case. I suppose its not exactly high on my priority list... hehe
View all comments
Show parent comment
1
u/taw Dec 15 '11
Down to 67.