Skip to content

Instantly share code, notes, and snippets.

@naohaq
Created November 8, 2012 10:49
Show Gist options
  • Save naohaq/4038114 to your computer and use it in GitHub Desktop.
Save naohaq/4038114 to your computer and use it in GitHub Desktop.
FizzBuzz by sed script
#!/bin/sed -f
s/[05]$/& @Buzz/
s/[12346789]$/& @/
s/^[0-9]/@&/
T
{
:loop
s/@\([0-9]\)\(.* \)/\1@\2\1/
T l1
s/ 0/ /
s/ 1/ o/
s/ 2/ oo/
s/ 3/ ooo/
s/ 4/ oooo/
s/ 5/ ooooo/
s/ 6/ oooooo/
s/ 7/ ooooooo/
s/ 8/ oooooooo/
s/ 9/ ooooooooo/
b loop
}
:l1
s/ooo/x/g
s/^.*@.*x@/Fizz/
s/^.*@.*o@Buzz/Buzz/
s/@.*@//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment