Skip to content

Instantly share code, notes, and snippets.

@ben-ng
Created March 4, 2019 05:39
Show Gist options
  • Save ben-ng/6e98478161853c9c5f9898ad47df79b1 to your computer and use it in GitHub Desktop.
Save ben-ng/6e98478161853c9c5f9898ad47df79b1 to your computer and use it in GitHub Desktop.
FizzBuzz solved with data-flow programming in Bash.
#!/usr/bin/env bash
seq 1 100 | \
xargs -Ix -n1 echo "x + ((x % 3 == 0) + ((x % 5) == 0) * 2) * 1000" | \
bc | \
xargs -n1 printf "%04d\n" | \
sed 's/^1.*/Fizz/' | \
sed 's/^2.*/Buzz/' | \
sed 's/^3.*/FizzBuzz/' | \
sed 's/^0*//'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment