Legend

From Esolang
Jump to navigation Jump to search

Legend is an esolang made by User:Joe, employing a minimalistic syntax comprising of legendre symbols, operating on an infinite tape.

Syntax

A Legend program consists of n legendre symbols of the form

(a/p)

where a and p are natural numbers, and p is an odd prime.

In addition, no other characters are allowed, not even whitespace. Using characters other than (, ), /, or a digit will result in a crash.

Semantics

A Legend program consists of n legendre symbols, and every symbol must be different else the program with crash.

Each legendre symbol evaluates to 0, 1 or -1, corresponding to the following instruction table. The table tallies three members:

Command Description
0 Move the pointer to the right and flip the bit at the new location
1 Skip the next instruction if the current cell's bit is zero (0)
-1 Move the pointer to the left if the pointer index is greater than one (1)

A program executes inside of a loop that ends if, by the end of the program, the active cell's bit is 0.

Every program structure has infinitely many implementations, as there are infinitely many legendre symbols evaluating to the same number.

Examples

Hello, world!

The following program produces in its tape the bits of the ASCII character codes defining the text "Hello, World!". Each character code octet's bits represent from left to right the most significant bit (MSB) to the least significant (LSB). Please note that an adscititious zero-valued bit is adhibited in the desinent memory cell in order to terminate the program.

This is an example of the infinitely many Hello World's in Legend out there. Using the Python script ([1]) will generate a perfectly valid random and different Hello World.

(5/73)(3/103)(1/71)(7/73)(2/139)(4/79)(8/139)(6/107)(10/23)(9/7)(13/167)(12/127)(14/173)(11/29)(15/29)(16/199)(18/59)(17/79)(19/179)(20/17)(22/43)(23/127)(21/61)(25/13)(24/17)(27/103)(28/193)(26/173)(29/97)(30/47)(31/79)(32/109)(35/181)(37/163)(33/163)(39/173)(38/47)(34/53)(42/83)(36/173)(43/31)(41/79)(40/103)(44/67)(45/149)(46/71)(51/97)(49/3)(47/41)(48/79)(52/181)(50/181)(54/89)(53/23)(57/181)(55/67)(56/97)(59/157)(58/191)(62/137)(60/103)(61/181)(63/191)(64/53)(66/7)(67/131)(68/157)(65/3)(69/103)(70/157)(72/29)(71/157)(73/167)(75/41)(74/17)(77/197)(76/113)(82/89)(79/97)(78/181)(84/139)(81/67)(80/137)(87/37)(83/59)(85/59)(86/101)(92/89)(89/137)(88/157)(90/41)(91/193)(93/13)(95/163)(94/103)(97/139)(98/199)(96/31)(99/101)(100/181)(101/191)(103/53)(102/127)(107/193)(106/23)(109/59)(113/7)(104/139)(105/163)(110/53)(111/13)(115/83)(108/107)(112/89)(114/61)(119/11)(116/61)(117/163)(118/139)(122/13)(123/71)(120/109)(121/139)(124/47)(125/103)(127/107)(128/73)(126/83)(131/137)(129/83)(133/157)(134/97)(130/59)(132/191)(135/107)(136/113)(137/131)(138/59)(139/7)(140/83)(142/97)(141/139)(143/7)(145/79)(144/103)(149/157)(150/107)(147/89)(146/7)(152/107)(148/107)(151/191)(155/191)(156/31)(153/113)(154/89)(157/61)(158/73)(160/11)(159/191)(165/101)(162/197)(168/103)(161/67)(164/97)(166/131)(163/109)(167/199)(170/173)(172/107)(169/199)(171/193)(173/59)(256/7)(257/127)(174/19)(258/61)(262/139)(175/151)(176/197)(259/113)(260/67)(261/193)(264/181)(263/37)(266/193)(177/41)(178/53)(179/127)(267/199)(180/97)(181/101)(265/97)(182/17)(183/43)(268/61)(184/151)(269/199)(272/37)(185/29)(270/131)(273/11)(271/97)(274/61)(276/31)(186/151)(187/13)(188/197)(277/5)(278/7)(275/139)(189/13)(279/29)(282/5)(281/59)(190/167)

Implementations

:-module(i,[main/1]). :-use_module(library(dcg/basics)). +[A/P|S]-->"(",number(A),"/",number(P),")",(+S;{S=[]}). \[]. \[H|T]:- \+ member(H,T),\T. 1-0. 0-1. []*I*H*V:-reverse(H,X),append(X,V,S),reverse(S,D),atomics_to_string(D,E),writeln(E),(V=[0|_];I*I*H*V). [2|R]*I*H*V:-(H=[],B=1,F=H;H=[A|F],A-B),R*I*F*[B|V]. [1|R]*I*H*[A|V]:-(A=1,G=[A|H],F=V;G=H,F=[A|V]),R*I*G*F. [0,F|R]*I*H*[A|V]:-(A=0,S=[F|R];S=R),S*I*H*[A|V]. main([C]):-open(C,read,Q),read_string(Q,_,Z),string_codes(Z,T),close(Q),+(F,T,[]),\F,maplist([A/P,L]>>(J is A^((P-1)//2)mod P,(J is P-1->L=2;L=J)),F,G),G*G*[]*[0].