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-02 21:33

syntax error at -e line 1, near "say !"

Name: Anonymous 2016-12-02 21:52

>>2
you need use 5.010; at least to use say(), otherwise just print and add a new line character.

Name: Anonymous 2016-12-02 22:27

>>3
Please be considerate and post portable code next time. My main IRIX machine only has Perl 5.5.

Name: Anonymous 2016-12-03 0:01

>>4
I think this is Perl 5.5 compatible:
sub say ($) { print $_[0] . $/ }

Name: Anonymous 2016-12-03 3:01

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

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 ? "" : "|!''");
}

Name: Anonymous 2016-12-04 0:24

>>7
??? that doesn't work:
ass(10) ==> !''<<!''<<!''<<!'' ==> 8

Name: Anonymous 2016-12-04 5:44

Real men let others test their code

Name: Anonymous 2016-12-04 6:30

10 get check it

Name: <--- check 2016-12-04 19:33

>>10
Nice.

Name: Anonymous 2016-12-06 4:19

>>11
sweet dubs bro

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