#!perl -pl s!(.*?)(b|mi|tho)!"+($1)*1E".(4-length$2)*3!eg;s/ h/00/g;y/y/0/;s#[a-z]+#$_=$&,'+'./te|lv/.(1+index"x /,.'_^",pack h2,$_)#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
pack, my love !
#!perl -pl s!(.*?)(b|mi|tho)!"+($1)*1E".(4-length$2)*3!eg;s/ h/00/g;y/y/0/;s#[a-z]+#$_=$&,'+'./te|lv/.(1+index"x /,.'_^",pack'h2',$_)#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
1E3 < 1000 ;-)
#!perl -pl s!(.*?)(b|mi|tho)!"+($1)*1E".(4-length$2)*3!eg;s/ h/00/g;y/y/0/;s#[a-z]+#$_=$&,'+'./te|lv/.(1+index-ontwthfofisiseeini__el,''&$_)/2#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
#!perl -pl s!(.*?)(b|mi|tho)!"+($1)*10**".(4-length$2)*3!eg;s/ h/00/g;y/y/0/;s#[a-z]+#$_=$&,'+'./te|lv/.(1+index-ontwthfofisiseeini__el,''&$_)/2#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
#!perl -pl s!(.*?)(b|mi|tho)\w+!"+($1)*10**".(4-length$2)*3!eg;s/ h/00/g;y/y/0/;s#[a-z]+#$_=$&,'+'./te|lv/.(1+index-ontwthfofisiseeini__el,''&$_)/2#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
Oops, sorry for the bad post before...
This one looks better :)
#!perl -pl s!(.*?)(b|mi|tho)\w+!"+($1)*10**".(4-length$2)*3!eg;s/ h\w+/00/g;y/y/0/;s#[a-z]+#$_=$&,'+'./te|lv/.(1+index-ontwthfofisiseeini__el,''&$_)/2#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
#!perl -pl $[=1;s!(.*?)(b|mi|tho)\w+!"+($1)*10**".(4-length$2)*3!eg;s/ h\w+/00/g;s#[a-z]+#$_=$&,/../,'+'.((index-ontwthfofisiseeiniBKel,$&)/2*(1+9*/y/)+10*/te|lv/)#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
#!perl -pl $[=1;s!(.*?)(b|mi|tho)\w+!"+($1)*10**".(4-length$2)*3!eg;s/ h\w+/00/g;s#[a-z]+#$_=$&,/../,$a=(index-ontwthfofisiseeiniBKel,$&)/2*(1+9*/y/)+10*/te|lv/,"+$a"#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
$[ ? Its use is highly discouraged.
My perl5 pocket reference says: Do not use - but hey!, this is golf!
#!perl -pl $[=1;s!(.*?)(b|mi|tho)\w+!"+($1)*10**".(4-length$2)*3!eg;s/ h\w+/*100/g;s#[a-z]+#$_=$&,/../,$a=(index zontwthfofisiseeiniBKel,$&)/2*(1+9*/y/)+10*/te|lv/,"+$a"#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
input : one hundred five output : yeepee :)
#!perl -pl s!(.*?)(b|mi|tho)\w+!"+($1)*10**".(4-length$2)*3!eg;s/ h\w+/*100/g;s#[a-z]+#$_=$&,/../,$a=int((index zeontwthfofisiseeiniBKel,$&)/2)*(1+9*/y/)+10*/te|lv/,"+$a"#eg;$_=eval;s/.(?=(...)+$)/$&,/g |
#!perl -pl
%t=qw!on 1 tw 2 th 3 fo 4 fi 5 si 6 se 7 ei 8 ni 9 el 11 b 9 tho 3 m 6!;s/(.*?)(b|m|tho)\w+/+($1)*10**$t{$2}/g;s/ h\w+/*100/g;s#[a-z]+#$_=$&,/../,$a=$t{$&}*(1+9*/y/)+10*/te|lv/,"+$a"#eg;$_=eval;s/.(?=(...)+$)/$&,/g
|
Catching Michael fast...
#!perl -pl
%t=qw!on 1 tw 2 th 3 fo 4 fi 5 si 6 se 7 ei 8 ni 9 el 11 b 9 tho 3 m 6!;s/(.*?)(b|m|tho)\w+/+($1)*10**$t{$2}/g;s/ h\w+/*100/g;s#[a-z]+#$_=$&,/../,$a=$t{$&}*(1+9*/ty/)+10*/te|lv/,"+$a"#eg;$_=eval;s/.(?=(...)+$)/$&,/g
|
Last post as beginner, last time in top-ten... ;-)
you haven't been a beginner for a while, Philippe :)
#!perl -pl
%t=(on,1,tw,2,th,3,fo,4,fi,5,si,6,se,7,ei,8,ni,9,el,11,b,9,tho,3,mi,6);sub _{$_=pop;/../;$t{$&}*(1+9*/ty/)+10*/te|lv/}s/(.*?)(b|mi|tho)\w+/+($1)*10**$t{$2}/g;s/ h\w+/*100/g;s/[a-z]+/+_($&)/g;$_=eval;s/.(?=(...)+$)/$&,/g
|
#!perl -pl
%t=qw#ze 0 on 1 tw 2 th 3 fo 4 fi 5 si 6 se 7 ei 8 ni 9 te 0 el 11 b 9 m 6 tho 3#;sub _{$_=pop;/../;$t{$&}*(1+9*/ty/)+10*/te|lv/}s/([^(]*?)(b|m|tho)\w+/+($1)*10**$t{$2}/g;s/ h\w+/*100/g;s/[a-z]+/+_($&)/g;$_=eval;s/.(?=(...)+$)/$&,/g
|
#!perl -pl
%t=qw#ze 0 on 1 tw 2 th 3 fo 4 fi 5 si 6 se 7 ei 8 ni 9 te 0 el 11 b 9 m 6 tho 3#;
sub _{$_=pop;/../;$t{$&}*(1+9*/ty/)+10*/te|lv/}s/([^(]*?)(b|m|tho)\w+/+($1)*10**$t{$2}/g;s/ h\w+/*100/g;s/([a-z]+)/+_($1)/g;$_=eval;s/(\d)(?=(\d{3})+$)/$1,/g
|
#!perl -l $_="one hundred sixty two million three thousand two hundred ninety nine"; s!(.*?)(b|mi|tho)\w+!"+($1)*10**".(4-length$2)*3!eg; print; s/ h\w+/00/g; print; y/y/0/; print; s#[a-z]+#$_=$&,'+'./te|lv/.(1+index-ontwthfofisiseeini__el,''&$_)/2#eg; print; $_=eval; print; s/.(?=(...)+$)/$&,/g; print; |
#!perl -pl
%t=qw#ze 0 on 1 tw 2 th 3 fo 4 fi 5 si 6 se 7 ei 8 ni 9 te 0 el 11#;
%e=qw#b 9 m 6 tho 3#;
sub _{
$a=pop;
($b)=($a=~/(..)/);
return 10* $t{$b} if $a=~/ty/;
return 10+ $t{$b} if $a=~/te|lv/;
$t{$b}
}
1while s/([^()]*?) (b|m|tho)\w+ ?([^()]*)/($1)*10**$e{$2}+($3)/;
s/(\w+) h\w+/100*_$1/eg;
s/([a-z]+)/+_($1)/g;
$_=eval;
s/(\d)(?=(\d{3})+$)/$1,/g;
|
Like the Little Regex Engine... "I think I can"... improve this solution ;-)
There _does_ seem to be some room manoeuvre
#!perl -pl
%t=(
'zero'=> '0',
'one'=> '1',
'two'=> '2',
'three'=> '3',
'four'=> '4',
'five'=> '5',
'six'=> '6',
'seven'=> '7',
'eight'=> '8',
'nine'=> '9',
'ten'=> '10',
'eleven'=> '11',
'twelve'=> '12',
'thirteen'=> '13',
'fourteen'=> '14',
'fifteen'=> '15',
'sixteen'=> '16',
'seventeen'=> '17',
'eighteen'=> '18',
'nineteen'=> '19',
'twenty'=> '20',
'thirty'=> '30',
'forty'=> '40',
'fifty'=> '50',
'sixty'=> '60',
'seventy'=> '70',
'eighty'=> '80',
'ninety'=> '90',
);
s/([^()]*) billion ?([^()]*)/($1)*10**9+($2)/;
s/([^()]*) million ?([^()]*)/($1)*10**6+($2)/;
s/([^()]*) thousand ?([^()]*)/($1)*10**3+($2)/;
s/(\w+) hundred/$t{$1}*100/eg;
s/([a-z]+)/+$t{$1}/g;
$_=eval;
1 while s/(\d)(\d{3})(,|$)/$1,$2$3/;
|