Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# for x<-1..?d,do: IO.puts(if rem(x,3)==0 or rem(x,5)==0,do: (if rem(x,3)==0,do: "Fizz",else: "")<>(if rem(x,5)==0,do: "Buzz",else: ""),else: x)
# for x<-1..?d,do: IO.puts(if rem(x,3)>0 and rem(x,5)>0,do: x,else: (if rem(x,3)>0,do: "",else: "Fizz")<>(if rem(x,5)>0,do: "",else: "Buzz"))
# for x<-1..?d,do: IO.puts(if rem(x,3)>0&&rem(x,5)>0,do: x,else: (if rem(x,3)>0,do: "",else: "Fizz")<>(if rem(x,5)>0,do: "",else: "Buzz"))
# for x<-1..?d,do: IO.puts if rem(x,3)>0&&rem(x,5)>0,do: x,else: (if rem(x,3)>0,do: "",else: "Fizz")<>(if rem(x,5)>0,do: "",else: "Buzz")
# for x<-1..?d,do: IO.puts if rem(x,3)>0&&rem(x,5)>0,do: x,else: "#{(if rem(x,3)<1,do: "Fizz")}#{(if rem(x,5)<1,do: "Buzz")}"
# for x<-1..?d,do: IO.puts if rem(x,3)>0&&rem(x,5)>0,do: x,else: "#{rem(x,3)<1&&"Fizz"||""}#{rem(x,5)<1&&"Buzz"||""}"
# for x<-1..?d,do: IO.puts if rem(x,3)>0&&rem(x,5)>0,do: x,else: (rem(x,3)<1&&"Fizz"||"")<>(rem(x,5)<1&&"Buzz"||"")
# for x<-1..?d,do: IO.puts rem(x,3)>0&&rem(x,5)>0&&x||(rem(x,3)<1&&"Fizz"||"")<>(rem(x,5)<1&&"Buzz"||"")
# for x<-1..?d,do: IO.puts (z=(rem(x,3)<1&&"Fizz"||"")<>(rem(x,5)<1&&"Buzz"||""))&&z==""&&x||z
# Current best, 89 characters:
for x<-1..?d,z=(rem(x,3)<1&&"Fizz"||"")<>(rem(x,5)<1&&"Buzz"||""),do: IO.puts z==""&&x||z
  • ?d == 100.
  • z evaluates to at least "", which is a truthy value allowing the print to run.
  • Remainder <1 saves 1 character over ==0.
  • Operator precedence used here: == or <, then &&, then ||.
  • Omitting brackets on IO.puts saves 1 character.
  • ,do: is 1 character shorter than do end.

henrik commented Nov 20, 2015

88! Using a twist on your own <1 trick:

for x<-1..?d,z=(rem(x,3)<1&&"Fizz"||"")<>(rem(x,5)<1&&"Buzz"||""),do: IO.puts z>""&&z||x

henrik commented Nov 20, 2015

87!

for x<-1..?d,z=(rem(x,3)<1&&"Fizz"||"")<>(rem(x,5)<1&&"Buzz"||""),do: IO.puts""<z&&z||x

emson commented Nov 20, 2015

oh wow... I'll have to update FizzBuzz ... meh ;o)

Owner

zyro commented Nov 20, 2015

I love the z>"" to ""<z flip to get rid of the preceding whitespace!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment