Last active
August 27, 2021 15:10
-
-
Save gdejohn/d6a4af13bcbb0147d568 to your computer and use it in GitHub Desktop.
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 (i in 1..100) sum {for (j->k in [3->"Fizz", 5->"Buzz"]) if (j.divides(i)) k} else i}.each(print); |
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
import Safe.Foldable (foldr1Def) | |
fizzbuzz = [foldr1Def (show i) (++) [k | (j,k) <- [(3,"Fizz"), (5,"Buzz")], rem i j == 0] | i <- [1..]] |
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
import static java.util.Map.entry; | |
import static java.util.stream.IntStream.range; | |
import java.util.Map.Entry; | |
import java.util.stream.Stream; | |
public class FizzBuzz { | |
public static void main(String[] args) { | |
range(1, 100).mapToObj( | |
i -> Stream.of(entry(3, "Fizz"), entry(5, "Buzz")).filter( | |
entry -> i % entry.getKey() == 0 | |
).map(Entry::getValue).reduce(String::concat).orElse(String.valueOf(i)) | |
).forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment