?d
is100
(ASCII code for d)for …,this,do
abuses a for-comprehension filter.this
runs on each iteration and would skip if returning a falsy value.- Since
IO.write
returns a truthy value, we can chainf||b||r.(1,n)
to only output the bare number if Fizz or Buzz did not output.
#ElixirGolf FizzBuzz: https://twitter.com/elixirgolf/status/665139870818574336
# Shortest (91 chars): | |
for n<-1..?d,r=&(rem(n,&1)==0&&IO.write&2)do;f=r.(3,"Fizz");b=r.(5,"Buzz");f||b||r.(1,n)end | |
# If newlines are required (99 chars): | |
for n<-1..?d,r=&(rem(n,&1)==0&&IO.write&2),do: (f=r.(3,"Fizz");b=r.(5,"Buzz");f||b||r.(1,n);:io.nl) | |
# Other solutions: | |
for n<-1..?d,r=&(rem(n,&1)==0&&IO.puts&2),do: r.(15,"FizzBuzz")||r.(3,"Fizz")||r.(5,"Buzz")||r.(1,n) | |
for n<-1..?d,do: Enum.find [{15,"FizzBuzz"},{3,"Fizz"},{5,"Buzz"},{1,n}],fn({d,t})->rem(n,d)==0&&IO.puts(t)end |
This comment has been minimized.
This comment has been minimized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Great... thanks for the descriptions really helpful - also like the conditions of
1==1&&IO.write "match"