From Esolang
Jump to navigation Jump to search

24 is an esoteric programming language that only works if the last 2 digits of the current year are before or equal to 24. All it does is print "ham n eggs" if the year fits the previously talked about requirements.

Scratch interpreter

Common Lisp implementation

The following implementation in Common Lisp can be optionally driven by a user input or an automatic detection of the current year:

(defun interpret-24 (&key (interactive-p NIL))
  "Launches the 24 interpreter, either evaluating the current year, or
   if INTERACTIVE-P is true, queries the standard input for a year to
  (declare (type boolean interactive-p))
  (let ((probed-year
          (if interactive-p
            (loop do
              (format T "~&Please enter a year: ")
              (let ((input (read-line NIL NIL "")))
                (declare (type string input))
                  (return   (parse-integer input))
                  (error () (format T "~&The input ~s is no valid year." input)))))
            (nth-value 5
    (declare (type integer probed-year))
    (let ((year-as-string (format NIL "~a" probed-year)))
      (declare (type string year-as-string))
      (let ((last-two-year-digits
                (subseq year-as-string
                  (max 0 (- (length year-as-string) 2))
                  (length year-as-string)))))
        (declare (type (integer 0 99) last-two-year-digits))
        (when (<= last-two-year-digits 24)
          (format T "~&ham n eggs"))))))

Python Implementation

from datetime import *
if year%100<25:
    print('ham n eggs')

An alternative that allows the user to specify the year using the -a argument.

import sys
from datetime import *
if len(sys.argv)>1 and sys.argv[-1]=='-a':
    year=input('Enter year: ')
    if not year.isdigit():
        print('Invalid year')
if year%100<25:
    print('ham n eggs')