Skip to content

Instantly share code, notes, and snippets.

@pete
Created September 20, 2025 14:32
Show Gist options
  • Save pete/538ca3a5897da6174b969d10c0add0d6 to your computer and use it in GitHub Desktop.
Save pete/538ca3a5897da6174b969d10c0add0d6 to your computer and use it in GitHub Desktop.
This works as-is on both Linux and Plan 9. I wrote it mainly to have something interesting to put on the screen for the
screenshots I added for the RISC-V Slackware image for the DevTerm ( https://stream.debu.gs/?id=1077 ).
The sed is kind of ugly but one instruction per line simplifies the awk. The `-E` has to be removed for this code to run
on Plan 9. The other change needed to run it on Plan 9 is you'd have to change /dev/fd/0 to just /fd/0.
`,` is unimplemented. Since we're reading the program from stdin, we can't read other input. This could be fixed by
generating a program and redirecting it to a file, or using a different fd, but that wouldn't be as funny and it is a
huge pain to do the latter approach in a Bourne-alike.
echo '++++[->++++<]>[-<+++++>>+++++++>++<<]<------.>>+++++.--.+.>.<[-<+>>>+
<<]>[--<++>>-<]>---.+++++++++++++.+.<<<.>>>-------.---.<<<--.>.>>+++.-------.++.++
[->+<<+>]>++++++.<<.<<.>[-<<->>]<<++++.[>>>--<<<-]>>>+.' | sed -E 's/(.)/\1\n/g' |
awk 'BEGIN{print "BEGIN{p=0;"}END{print "}"}/\./{print "printf \"%c\",a[p]"}/
\+/{print "a[p]++"}/-/{print "a[p]--"}/</{print "p--"}/>/{print "p++"}/\[/{print
"while(a[p]){"}/\]/{print "}"}' | awk -f /dev/fd/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment