Heisse News

Quicksearch

Kategorien

Letzte Google-Suchen

xkcd 949 solutionxkcd 949 solution

overcommit_memory=2

entropia 0xc000007b

gesext Investment Touch & Sex

watch my girl fricrd videos.com

screenshot in vector format

koma script tex gyre

Archives

Display comments as
(Linear | Threaded)

Did the same stuff in Perl and it looks a little shorter but it is dog slow. :-/

@u=(C..H,'sqrt');@b=qw(+ * - / **);sub i{my$s=shift;if($s=~/U/){$x=$s,

$x=~s/U/$_/,i($x) for@u}elsif($s=~/B/){$x=$s,$x=~s/B/$_/,i($x) for@b}

else{($e=eval$s)&&($expr{$e}=$s)}}i("(((U(4)BU(4))BU(4)))BU(4)");i(

"(U(4)BU(4))B(U(4)BU(4))");($_="$_: $expr{$_}\n"),s/F.*?\)/4!/g,

s/C.*?\)/sqrt(.4bar)/g,s/D.*?\)/sqrt(.4)/g,s/G.*?\)/.4'/g,

s/E.*?\)/.4/g,s/H.*?\)/4/g,print for 1..100;sub H{shift};sub E{(shift)

/10};sub G{(shift)/9};sub D{sqrt((shift)/10)};sub C{sqrt((shift)/9)}

sub F{$_[0]==0||$_[0]*F($_[0]-1)};

@u=(C..H,'sqrt');@b=qw(+ * - / **);sub i{my$s=shift;if($s=~/U/){$x=$s,

$x=~s/U/$_/,i($x) for@u}elsif($s=~/B/){$x=$s,$x=~s/B/$_/,i($x) for@b}

else{($e=eval$s)&&($expr{$e}=$s)}}i("(((U(4)BU(4))BU(4)))BU(4)");i(

"(U(4)BU(4))B(U(4)BU(4))");($_="$_: $expr{$_}\n"),s/F.*?\)/4!/g,

s/C.*?\)/sqrt(.4bar)/g,s/D.*?\)/sqrt(.4)/g,s/G.*?\)/.4'/g,

s/E.*?\)/.4/g,s/H.*?\)/4/g,print for 1..100;sub H{shift};sub E{(shift)

/10};sub G{(shift)/9};sub D{sqrt((shift)/10)};sub C{sqrt((shift)/9)}

sub F{$_[0]==0||$_[0]*F($_[0]-1)};

Impressive I especially like the result that it finds for the 1:

1: (sqrt(4)**sqrt(4))**(sqrt(4)-sqrt(4))

That’s almost as ofuscated as your code :-)

1: (sqrt(4)**sqrt(4))**(sqrt(4)-sqrt(4))

That’s almost as ofuscated as your code :-)

Now it's even shorter and gives nicer looking results:

http://paste-it.net/684

http://paste-it.net/684

Very nice. I had :x: as infix constructors once, but had some problems them. I also like the use of monads to handle evaluation errors, something I considered, but did not do (I yet have to learn more about Monads).

I especially like how you do not specify a monad for eval, and it just falls into place when it is used in the list comprehension.

I especially like how you do not specify a monad for eval, and it just falls into place when it is used in the list comprehension.

If I understand your code correctly, you're using exponentiation as one of your operators. (I don't really know Haskell, though.) In both Python and C#, the '^' operator is bitwise xor, not exponentiation.

Neither is needed, though. I was able to get all 100 numbers using just addition, subtraction, multiplication, and division. (This was in Common Lisp, which does ratios for integer division; perhaps C#'s and Python's division operators don't work in the same way. OTOH, I still got all the numbers when using truncate instead of /, so who knows?)

Neither is needed, though. I was able to get all 100 numbers using just addition, subtraction, multiplication, and division. (This was in Common Lisp, which does ratios for integer division; perhaps C#'s and Python's division operators don't work in the same way. OTOH, I still got all the numbers when using truncate instead of /, so who knows?)

Comment about the list monad thing: I agree that it is a nice example of using the list monad, but I find in this case it is not really necessary to go the monad way when list comprehension offers the same:

all_combos = concat [ groupings v1 v2 v3 v4 b1 b2 b3 | v1 <- zeroaries, v2 <- zeroaries, v3 <- zeroaries, v4 <- zeroaries, b1 <- binaries, b2 <- binaries, b3 <- binaries]

(Where < is supposed to display as an left angle bracket.)

Cheers!

Jan

all_combos = concat [ groupings v1 v2 v3 v4 b1 b2 b3 | v1 <- zeroaries, v2 <- zeroaries, v3 <- zeroaries, v4 <- zeroaries, b1 <- binaries, b2 <- binaries, b3 <- binaries]

(Where < is supposed to display as an left angle bracket.)

Cheers!

Jan

Personally, I often find list monad expressions easier to read than list comprehensions, but thats personal taste of course. In the end, it’s syntactic sugar for the same thing, AFIAK.

apropos comprehension, this

http://groups.csail.mit.edu/pag/reading-group/wadler-monads.pdf

is a really nice read.

http://groups.csail.mit.edu/pag/reading-group/wadler-monads.pdf

is a really nice read.

## Trackbacks

I came across the FourFours problem recently. Stated succinctly, it asks: what are the ways to calculate each of the integers from 1 to 100 with formulas which use the digit four exactly four times? (No digits other than four can be used at all.) Peopl

Weblog:Phil! GregoryTracked:Dec 11, 00:24