Bgt

From Esolang
Jump to navigation Jump to search

Bgt is a joke esoteric programming language speedran by Cinnamony. Let's see how long it takes to write this one.

Commands

Command Description
P prints the character in front of it
K prints the input
L prints the 99 bottles of beer on the wall program
J print the FizzBuzz program
Z truth-machine

Examples

Hello World

PHPePlPlPoP,P PWPoPrPlPdP!

Cat

K

99 Bottles of Beer

L

FizzBuzz

J

Truth Machine

Z

Time

00:02:22.29

Implementations

An implementation in Common Lisp shall be provided:

(defun interpret-Bgt (code)
  "Interprets the piece of Bgt source CODE and returns NIL."
  (declare (type string code))
  (let ((position 0))
    (declare (type fixnum position))
    (symbol-macrolet
        ((current-token
          (the character
            (char code position)))
         (eof-p
          (the boolean
            (not (array-in-bounds-p code position)))))
      (loop until eof-p do
        (case current-token
          (#\P
            (incf position)
            (when eof-p
              (error "Expected at character to print, encountered EOF."))
            (format T "~c" current-token)
            (incf position))
          (#\K
            (format T "~&>> ")
            (format T "~a" (read-line))
            (clear-input)
            (incf position))
          (#\L
            (loop for number-of-bottles of-type (integer -1 99) from 99 downto 1 do
              (format T "~&~d ~:*bottle~p of beer on the wall,~%~
                         ~:*~d ~:*bottle~p of beer.~%~
                         Take one down, pass it around,~%~
                         ~[No~:;~d~] ~:*bottle~p of beer on the wall.~2%"
                number-of-bottles (decf number-of-bottles) number-of-bottles))
            (incf position))
          (#\J
            (loop for counter of-type (integer 1 101) from 1 to 100 do
              (format T "~&~a"
                (cond
                  ((zerop (mod counter 15)) "FizzBuzz")
                  ((zerop (mod counter  3)) "Fizz")
                  ((zerop (mod counter  5)) "Buzz")
                  (T                         counter))))
            (incf position))
          (#\Z
            (format T "~&>> ")
            (let ((input (parse-integer (read-line))))
              (declare (type integer input))
              (clear-input)
              (if (zerop input)
                (format T "~&0")
                (loop initially (fresh-line) do (format T "1"))))
            (incf position))
          (otherwise
            (error "Invalid character at position ~d: ~s." position current-token)))))))