Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge - Perl Numerals

Name: Anonymous 2016-12-02 21:10

Perl numerals is a way to represent natural numbers in Perl wihtout the use of numeric literals, examples:
say !''>>!''; # 0
say !''; # 1
say !''<<!''; # 2
say !''<<!''|!''; # 3
say !''<<!''<<!''; # 4
say !''<<!''<<!''|!''; # 5


Your task is to write a function that given a natural number returns a valid Perl numeral expression that evaluates into that same number.

Name: Anonymous 2016-12-03 3:02

>>6
ah fuck

function ass(n) {
if (n === 0)
return "''>>!''"
return "!''"
+ "<<!''".repeat(Math.floor(Math.log2(n)))
+ (n % 2 === 0 ? "" : "|!''");
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List