Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Challenge: Chasing Knuth's Conjecture

by Roy Johnson (Monsignor)
on Mar 29, 2005 at 17:55 UTC ( #443209=note: print w/replies, xml ) Need Help??

in reply to Re: Challenge: Chasing Knuth's Conjecture
in thread Challenge: Chasing Knuth's Conjecture

I took your ideas for avoiding re-testing things and revamped my sieve. This generates all the answers that don't require factorial on anything higher than whatever you set (350 gets me all solutions for 1..30). It runs in about 5 seconds on my 1 GHz PC with that setting.
use strict; use warnings; use bigint; # How high a number are you willing to factorialize? my $factorial_limit = 999; # Pre-cache them to save on calls my @factorials = do { my $last_fact = 1; (0, 1, map { $last_fact *= $_ + } 2..$factorial_limit) }; # What's the biggest number you want to print? my $print_up_to = 200; # Each element of @formulas is an an op-string: # a string of Fs and Ss, indicating factorial # and square root, in order applied to get the # index my %formulas = (3 => '3'); my @unapplied = ([3, '3']); while (@unapplied) { my ($v, $ops) = @{shift(@unapplied)}; # Apply factorial if ($v <= $factorial_limit) { my $fv = $factorials[$v]; my $fops = $ops . 'F'; if (not exists $formulas{$fv}) { push @unapplied, [$fv, $fops]; $formulas{$fv} = $fops; } } # Apply sqrt $v = int(sqrt($v)); $ops .= 'S'; if (not exists $formulas{$v}) { push @unapplied, [$v, $ops]; $formulas{$v} = $ops; } } for (sort { $a <=> $b } keys %formulas) { last if $_ > $print_up_to; print "$_: $formulas{$_}\n"; }
Update: pregenerated factorials to save time; also put in a limit on how high to print, so the huge numbers don't show up. Even taking factorials as high as 999 (takes 30-40 seconds), there's no solution for 38.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^3: Challenge: Chasing Knuth's Conjecture
by tall_man (Parson) on Mar 29, 2005 at 20:07 UTC
    I computed an answer for 38 with my modified version of hv's program, using logs. The result is:
    "sssssssssfsssssssssssfssssssfssssssfssssssfssssssssssfssssssssfssssss +ssfssssssfssssssfssssfssssssssfsfssfssssssfsssssfssfsfssff"

    I confirmed this answer with Math::Pari, and it is correct. The highest factorial required is 1861.

      My code looks like it agrees with yours; I set the factorial limit to 5000, and it ran for 20 or 30 minutes, I think. 64 is the first skip at that setting.

      I did a simple translation of your Inline C sub into Perl, and it is still very fast. Running it for 64 took 33 seconds, and it popped out:

      64 => sssssssssfssssssfsssssssssssssfsssssssssssfssssssssssssfssssssss +ssfssssssf ssssssssfsssssssssfsssssssssssfsssssssfssssssfsssssssssssfssssssssfsss +ssssssssfs sssssfssssssfssssssfssssssssssfssssssssfssssssssfssssssfssssssfssssfss +ssssssfsfs sfssssssfsssssfssfsfssff biggest tried was 5071

      Code follows.

      Caution: Contents may have been coded under pressure.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://443209]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2019-11-20 14:31 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (97 votes). Check out past polls.