Created
May 8, 2018 08:17
-
-
Save bradenbest/ffb85e2ea0b94daeac6cc9993896465e to your computer and use it in GitHub Desktop.
99 bottles of beer in dc (unix)
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
#!/usr/bin/dc | |
[ | |
dc(1), or desktop calculator, is a unix program. It is one of the oldest, predating even the C programming language. | |
dc is slightly easier than brainfuck | |
---- | |
This version of 99 bottles is pretty rudimentary and lacks proper punctuation | |
]c | |
100sg # register g: (int) 100 | |
[ bottle(s) of beer]sh # register h: (str) " bottle(s) of beer" | |
[ on the wall ]si # register i: (str) " on the wall " | |
[ take one down pass it around ]sj # register j: (str) " take one down pass it around " | |
[ lgn # load g and print without newline -> "99" | |
lhn # h -> " bottle(s) of beer" | |
lin # i -> " on the wall " | |
lgn # g -> "99" | |
lhn # h -> " bottle(s) of beer" | |
ljn # j -> " take one down..." | |
lg1-n # g - 1 -> "98" | |
lhn # h -> " bottle(s) of beer" | |
lip # i -> " on the wall " | |
]sf # register f: (str) macro | |
[ lg1-sg # load g, sub 1, save g | |
lfx # load f, execute | |
lg0<a # load g, push 0 to stack, if 0 < g, execute macro a | |
]dsax # register a: (str) macro; d = dupe, since s pops the top of stack. 'd sa x' is equivalent to 'sa la x' | |
[(good luck drinking -1 bottles of beer tho)]p # print the string between [] |
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
#!/usr/bin/dc | |
100sg[ bottle(s) of beer]sh[ on the wall ]si[ take one down pass it around ]sj[lgnlhnlinlgnlhnljnlg1-nlhnlip]sf[lg1-sglfxlg0<a]dsax[(good luck drinking -1 bottles of beer tho)]p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment