?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 thando end
.
Created
November 15, 2015 18:42
-
-
Save zyro/e60e75ef3a3c3f08e5ef to your computer and use it in GitHub Desktop.
#ElixirGolf FizzBuzz https://twitter.com/elixirgolf/status/665139870818574336
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
87!
for x<-1..?d,z=(rem(x,3)<1&&"Fizz"||"")<>(rem(x,5)<1&&"Buzz"||""),do: IO.puts""<z&&z||x
oh wow... I'll have to update FizzBuzz ... meh ;o)
I love the z>""
to ""<z
flip to get rid of the preceding whitespace!
Using max
is shorter:
for i<-1..?d,do: IO.puts max"#{i}",(rem(i,3)<1&&"Fizz"||"")<>(rem(i,5)<1&&"Buzz"||"")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
88! Using a twist on your own
<1
trick: