?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.
Last active
November 15, 2015 18:50
-
-
Save henrik/6ca434c0c5cb66ed29d7 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great... thanks for the descriptions really helpful - also like the conditions of
1==1&&IO.write "match"