99bottles.bf 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. # 99 bottles of beer in Brainf*ck
  2. # Copyright (C) 2008 Raphael Bois
  3. # 1671 brainf*ck instructions.
  4. # Published under GPL v2
  5. Initialization
  6. ++ Counter for loop (a)
  7. >+ unused
  8. >++ Counter for loop (b)
  9. > Flag for 'no more'
  10. >+ Flag for not 'no more'
  11. >>> (5) to (7) : temporary values
  12. ++++++++++[->+>+>++++++++++<<<]>>> 10 10 100 in (8) (9) (10)
  13. >++++++++++ 10 in (11)
  14. [-
  15. >+++++ 50 in (12)
  16. >++++++++++ 100 in (13)
  17. >+++++++++++ 110 in (14)
  18. >++++++++ 80 in (15)
  19. >++++++++ 80 in (16)
  20. >+++ 30 in (17)
  21. >++++ 40 in (18)
  22. >+ 10 in (19)
  23. <<<<<<<<]
  24. +
  25. >-- + 48 '0' plus 1 in (12)
  26. >++ + 102 'f' plus 1 in (13)
  27. >+++++ + 115 's' plus 1 in (14)
  28. >-- + 78 'N' plus 1 in (15)
  29. >++++ + 84 'T' plus 1 in (16)
  30. >++ + 32 ' ' plus 1 in (17)
  31. >++++ + 44 comma plus 1 in (18)
  32. > + 10 LF plus 1 in (19)
  33. stuff for writing parts of the song
  34. >+ select stuff
  35. >+ select stuff
  36. >+ write song part 3
  37. >++ write song part 1
  38. >+ write song part 2
  39. >+ Flag for 'end of song'
  40. >++ Flag for not 'end of song'
  41. All bytes are at val plus 1
  42. Go back to (7) with final initialization step (remove 1 to all bytes)
  43. [-<]
  44. <<<<<<< at (0)
  45. [ loop (a)
  46. -
  47. >> at (2)
  48. [ loop (b)
  49. >>>>>>>> at (10)
  50. [ start loop
  51. <<<<<<< at (3)
  52. [->[-]
  53. print '(N|n)o more'
  54. >>>>>>>>>>>. '(N|n)'
  55. <----. 'o'
  56. >>>. ' '
  57. <<<--. 'm'
  58. ++. 'o'
  59. +++.+ 'r'
  60. <-.+ 'e'
  61. <<+<<<<<<<<
  62. ]+> at (4)
  63. [-<[-]>>>>> at (9)
  64. prints number (using (9) and (10))
  65. [>>>+<<<<+<+<+>>>-]<<<[->>>+<<<]> at (6)
  66. [>>>>>>+<<<<<<-]>>>>>[[-]>.<]<<<<[>>>>>-<<<<<-]>> at (9)
  67. [<<+<+<+>>>>-]<<<<[->>>>+<<<<]> at (6)
  68. [>>>>>>+<<<<<<-]>>>>>>.<<<<<[>>>>>-<<<<<-] at (7)
  69. memorize in (11) if (10) not 1
  70. >>>[-<<<+<+>>>>]<<<<[->>>>+<<<<]>-[[-]>>>>+<<<<]<<< at (4)
  71. ]+
  72. >>>>>>>> at (12)
  73. print ' bottle(s) of beer'
  74. >>>>>. ' '
  75. <<<<----. 'b'
  76. >----. 'o'
  77. +++++..- 'tt'
  78. <++++++++++. 'l'
  79. -------. 'e'
  80. <<[[-]>>>.<<<]>> 's' if (11)==1 ie if (10)!=1
  81. >>>>. ' '
  82. <<<----. 'o'
  83. <+. 'f'
  84. >>>>. ' '
  85. <<<<----. 'b'
  86. +++..+ 'ee'
  87. >+++.+ 'r'
  88. [>] at (20)
  89. +>+>[->+<<-<-
  90. print ' on the wall' DOT LF LF
  91. <<<. ' '
  92. <<<----. 'o'
  93. -. 'n'
  94. >>>. ' '
  95. <<<++++++. 't'
  96. <++. 'h'
  97. ---. 'e'
  98. >>>>. ' '
  99. <<<+++. 'w'
  100. <----. 'a'
  101. +++++++++++.. 'll'
  102. ------>---- reset to 'f' and 's'
  103. >---------- ---------- ---------- -- sets (15) to 'N'
  104. >>>++.-- DOT
  105. >.. LF LF
  106. >>>] at (22)
  107. >>>[->[-]<<<<<<<[<]<[-]>>[>]>>>>>]+ if end of song reset bottles counter
  108. >[-<[-] at (25)
  109. <<<< at (21)
  110. [->>[->+<<<<-
  111. print ' on the wall' COMMA ' '
  112. <<<. ' '
  113. <<<----. 'o'
  114. -. 'n'
  115. >>>. ' '
  116. <<<++++++. 't'
  117. <++. 'h'
  118. ---. 'e'
  119. >>>>. ' '
  120. <<<+++. 'w'
  121. <----. 'a'
  122. +++++++++++.. 'll'
  123. ------>---- reset (13) and (14) to 'f' and 's'
  124. >++++++++++ ++++++++++ ++++++++++ ++ sets (15) to 'n'
  125. >>>. comma
  126. <. ' '
  127. >>>>>>]<<]< at (20)
  128. [->>>>[-<<+< at (21)
  129. <<<++.-- DOT
  130. >. LF
  131. [<]<<<<<<<< at (3)
  132. [->[-]<]+> at (4)
  133. [-<[-]>
  134. >>>>>>>>>>>>. 'T'
  135. <<<-----. 'a'
  136. ++++++++++. 'k'
  137. ------. 'e'
  138. >>>>. ' '
  139. <<<----. 'o'
  140. -. 'n'
  141. <. 'e'
  142. >>>>. ' '
  143. <<<<-. 'd'
  144. >+. 'o'
  145. ++++++++. 'w'
  146. ---------. 'n'
  147. >>>. ' '
  148. <<<<---. 'a'
  149. >. 'n'
  150. <+++. 'd'
  151. >>>>. ' '
  152. <<<++. 'p'
  153. <---. 'a'
  154. >+++.. 'ss'
  155. >>>. ' '
  156. <<<<++++++++. 'i'
  157. >+. 't'
  158. >>>. ' '
  159. <<<<--------. 'a'
  160. >--. 'r'
  161. ---. 'o'
  162. ++++++. 'u'
  163. -------. 'n'
  164. <+++. 'd'
  165. ++>+++++ reset (13) and (14) to 'f' and 's'
  166. >>>>. comma
  167. <. ' '
  168. [<]<<<<<<< at (4)
  169. ]+
  170. >>>>>> at (10)
  171. decrements values
  172. -<<<+>>[<<[-]<+<+>>>>-]<<<<[>-<[-]]>[->>>+<<<]>[->->+++++++++<<]>>> at (10)
  173. >>[>]>>>>] at (24)
  174. <<<<] at (20)
  175. >>>>>>]+ at (26)
  176. <<<<<<<[<]< at (10)
  177. ]
  178. +<+
  179. <<<<<<+< at (2)
  180. -
  181. ]
  182. print 'Go to the store and buy some more' comma ' '
  183. >>>>>>>>>>[>]>>>>> at (25)
  184. [->[-]<]+> at (26)
  185. [-<[-]
  186. <<<<<<<<< at (16)
  187. -------------. 'G'
  188. <<----. 'o'
  189. >>>. ' '
  190. <<<+++++. 't'
  191. -----. 'o'
  192. >>>. ' '
  193. <<<+++++. 't'
  194. <++. 'h'
  195. ---. 'e'
  196. >>>>. ' '
  197. <<<-. 's'
  198. +. 't'
  199. -----. 'o'
  200. +++. 'r'
  201. <. 'e'
  202. >>>>. ' '
  203. <<<<----. 'a'
  204. >----. 'n'
  205. <+++. 'd'
  206. >>>>. ' '
  207. <<<<--. 'b'
  208. >+++++++. 'u'
  209. ++++. 'y'
  210. >>>. ' '
  211. <<<------. 's'
  212. ----. 'o'
  213. --. 'm'
  214. <+++. 'e'
  215. >>>>. ' '
  216. <<<. 'm'
  217. ++. 'o'
  218. +++.+ 'r'
  219. <.+ 'e'
  220. >>>>>. coma
  221. <. ' '
  222. >>>>>>>>>
  223. ]+
  224. Initialize last loop to print final '99 bottles of beer on the wall' DOT
  225. <[-]+<[-]<[-]<[-]+<<< at (19)
  226. [<]<[-]<[-]<[-]<[-] at (7)
  227. ++++++++++[->+>+>++++++++++<<<]>->->-
  228. <<<<<<[-]+<[-]<+<< at (0)
  229. ]