Gift

From Esolang
Jump to navigation Jump to search

Gift is a festive, joke esoteric language created by User:UW that has no practical uses. It takes your wish list as input, and outputs "coal" if you ask for something that is too expensive.

Input

The input can be made up of multiple lines, and is meant to represent a wish list. Here's an example:

a brand new car
a red sweater
10 candy bars maybe

Note that blank lines are ignored.

Output

Gift outputs one of two things:

  • the first character of each line, one after the other
  • the string "coal", if it decides that you've asked for something that is too expensive (see the explanation below)

Explanation

How does the interpreter know if something is too expensive?

Gift has no understanding of the words in the input, and simply uses a hash function for arbitrary reasons:

  1. For each line in the input, a hash is calculated (32-bit FNV-1a, case-insensitive). Spaces and tabs are ignored. The resulting hash is a 32-bit integer.
  2. If this integer is not a multiple of 4, the item on that line is declared as being too expensive. So, you will get coal more often than not. The hash can't be changed by simply adding more spaces or by changing a letter's case.
  3. If at least one item in the list is deemed too expensive, the output will simply be "coal". You won't be told what item caused that output.
  4. If no item is deemed too expensive, the first character of each line will be printed.

Examples

Successuful example

Large hoodie
orange socks

lemons maybe?

Output: Lol (aka the first character of each line)

Notice how the output contains no spaces, even if there is a blank line.

Failed example

Input:

a really nice car
brand new pc

Output: coal (because the second item is deemed too expensive)

Hello World

Hen
eight cute rabbits
light green paper
long piece of paper
orange socks
,+
_--
White pants
orange coat
really nice cardboard box
light green paper
dark pink sweater
!

Note: since Gift can't output spaces, it's replaced by a dash (_).

Another version by PSTF:

Huacors
eksjrngm
l3ryi
l3ryi
osur
,+
_--
Whizlg
oslfksk
rkshdrg
ldugve
dhoy8w
!

This is the result of random typing.

Quine

coal

Self-explanatory.

Besides that, there are 62 one-character quines:

\x01 \x05 \x11 \x15 \x19 \x1d ! % ) - 1 5 9 = A E I M Q U Y ] a e i m q u y } \x81 \x85 \x89 \x8d \x91 \x95 \x99 \x9d \xa1 \xa5 \xa9 \xad \xb1 \xb5 \xb9 \xbd \xc1 \xc5 \xc9 \xcd \xd1 \xd5 \xd9 \xdd \xe1 \xe5 \xe9 \xed \xf1 \xf5 \xf9 \xfd

Some characters are escaped and should be unescaped to work, \r and \t have a valid hash, but aren't valid as they're whitespaces.

99 bottles of beers

9isurhfmisuckjhr
9ursdfkhpodidl
_++
bfsiurchseopljtsoph5io
osojtpsei[ctp[esoxu[d
tusroylr.pjviftj[hso
tj9psorlyr5poyvruphl
--snip--

Too long.

XKCD Random Number

4aaa

6 interpreter

6kjserkxsdfkisrhfxerf

Interepters:

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

FNV_32_PRIME = 0x01000193

FNV1_32_INIT = 0x811c9dc5

import sys
if sys.version_info[0] == 3:
    _get_byte = lambda c: c
else:
    _get_byte = ord

def fnva(data, hval_init, fnv_prime, fnv_size):
    assert isinstance(data, bytes)

    hval = hval_init
    for byte in data:
        hval = hval ^ _get_byte(byte)
        hval = (hval * fnv_prime) % fnv_size
    return hval

def fnv1a_32(data, hval_init=FNV1_32_INIT):
    """
    Returns the 32 bit FNV-1a hash value for the given data.
    """
    return fnva(data, hval_init, FNV_32_PRIME, 2**32)

line1 = input("Enter the first line of your code (blank line to end program): ")
if line1 != "":
	line2 = input("Enter the 2nd line (blank to end): ")
	if line2 != "":
		line3 = input("Enter the 3rd line (blank to end): ")
		if line3 != "":
			line4 = input("Enter the 4th line (blank to end): ")
			if line4 != "":
				line5 = input("Enter the 5th line (blank to end): ")
				if line5 != "":
					line6 = input("Enter the 6th line (blank to end): ")
					if line6 != "":
						line7 = input("Enter the 6th line (blank to end): ")
						if line7 != "":
							line8 = input("Enter the 8th line (blank to end): ")

if fnv1a_32(line1) % 4 == 0 or fnv1a_32(line2) % 4 == 0 or fnv1a_32(line3) % 4 == 0 or fnv1a_32(line4) % 4 == 0 or fnv1a_32(line5) % 4 == 0 or fnv1a_32(line6) % 4 == 0 or fnv1a_32(line7) % 4 == 0 or fnv1a_32(line8) % 4 == 0:
	print("coal")
else:
	if line8 == "":
		if line7 == "":
			if line6 == "":
				if line5 == "":
					if line4 == "":
						if line3 == "":
							if line2 == "":
								if line1 == "":
									pass
								print(line1[0])
							print(line1[0] + line2[0])
						print(line1[0] + line2[0] + line3[0])
					print(line1[0] + line2[0] + line3[0] + line4[0])
				print(line1[0] + line2[0] + line3[0] + line4[0] + line5[0])
			print(line1[0] + line2[0] + line3[0] + line4[0] + line5[0] + line6[0])
		print(line1[0] + line2[0] + line3[0] + line4[0] + line5[0] + line6[0] + line7[0])
	print(line1[0] + line2[0] + line3[0] + line4[0] + line5[0] + line6[0] + line7[0] + line8[0])