rosetta/Universal_Lambda_Machine.bruijn

Problem description

:import std/Combinator .
:import std/Number/Binary .
:import std/Meta M
:import std/List .

# converts string to list of bits
str→blc map (c ∘ lsb)

:test (str→blc "0010") ([[1]] : ([[1]] : ([[0]] : {}[[1]])))

# converts list of bits to string
blc→str map [0 '0' '1']

:test (blc→str ([[1]] : ([[1]] : ([[0]] : {}[[1]])))) ("0010")

# evaluates BLC string
main str→blc → M.blc→meta+rest → &M.eval → blc→str

# --- tests ---

id "0010"

# 342 bit IO example
io "010100011010000000011000010110011110000010010111110111100001010110000000011000011111000000101111110110010111111011001011110100111010111100010000001011100101010001101000000000010110000101011111101111100000010101111011111011111100001011000000101111111010110111000000111111000010110111101110011110100000010110000011011000100000101111000111001110"

# quine example
quine "000101100100011010000000000001011011110010111100111111011111011010000101100100011010000000000001011011110010111100111111011111011010"

# 100 doors example
doors "0001000100010101000110100000010110000011001110110010100011010000000000101111111000000101111101011001011001000110100001111100110100101111101111000000001011111111110110011001111111011100000000101111110000001011111010110011011100101011000000101111011001011110011110011110110100000000001011011100111011110000000001000000111001110100000000101101110110"

# sieve of Eratosthenes example
primes "00010001100110010100011010000000010110000010010001010111110111101001000110100001110011010000000000101101110011100111111101111000000001111100110111000000101100000110110"

:test (main id) (empty)
:test (main io) ("11010")
:test (main quine) (quine)
:test (take (+20) (main doors)) ("10010000100000010000")
:test (take (+20) (main primes)) ("00110101000101000101")