Factor, 137 characters
USING: calendar kernel io math.order sequences ;
58 seconds hence
99999 "9" <repetition> concat
[ dup write over now after? ] loop 2drop
With comments,
! calendar => seconds hence now
! kernel => dup over loop 2drop
! io => write
! math.order => after?
! sequences => <repetition> concat
USING: calendar kernel io math.order sequences ;
! Push the stop time (58 seconds after now). This leaves 2 extra seconds
! for starting and stopping the script.
58 seconds hence
! Push a long string of "9"s. The best length is near 99999.
99999 "9" <repetition> concat
[
! Write the very long string of "9"s.
dup write
! If the stop time is after now, then loop.
over now after?
] loop
! Empty the data stack.
2drop
This script tries to print as many "9" digits as possible, without exceeding the time limit of one minute. The number of digits changes from run to run.
Output is 10 ^ 4_765_052_349 - 1, if I must display the number in an xterm.
$ time ~/park/factor/factor scratch.factor | tee out
99999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
...
999999999999999999 0m58.56s real 0m15.63s user 0m26.21s system
$ wc -c out
4765052349 out
Output is 10 ^ 22_843_571_562 - 1, if I never display the number.
$ time ~/park/factor/factor scratch.factor | wc -c
22843571562
0m58.32s real 0m50.27s user 0m19.50s system
Additional notes:
- Each
write
converts the string (Unicode codepoints) to a byte array (UTF-8). This conversion might waste time inside the loop. A faster program might make a byte array before the loop, and write the byte array inside the loop; but I cannot write a byte array to the default output stream, which is a character stream. I would have to use many characters to open a binary stream.
- A faster program might call setitimer(2) and handle SIGALRM after 58 seconds. I did not find a short way to call setitimer(2) from Factor.
1here is a proposed evaluation formula
magnitude / (characters^2 * time)
– Ming-Tang – 2011-02-20T05:32:01.580@Shinkirou I would measure my time in decades, so I will get a very huge score :P – None – 2011-02-25T22:41:52.527
16print '10' - since you haven't specified the base, this is using base-Graham's Number – Skizz – 2011-03-10T11:38:36.647
As per @Skizz smartass comment, I assume the integer has to consist solely of the digits 0-9 in base 10, so things like the literal strings "9e+999" or "9^9^9" or "Ackerman(9,9)" are out, even though they technically represent integers? – barrycarter – 2011-03-20T04:37:25.637
9So much for Ackerman(9,9) :P – JPvdMerwe – 2011-01-29T12:14:29.377
3Note that the results highly depend on the output device (/dev/stdout - slowest since it involves graphics, /dev/null - fastest cause it doesn't do anything, | wc -l - medium). – Alexandru – 2011-01-29T17:28:40.997
6The question should either restrict the size of the code
what is the highest number with 100 bytes of code
, or enforce a minimum numbergenerate a number, at least 9^1000) as pure digits with as few code as you can
. Searching for minimum and maximum the same time would need a conversion function, how to judge on smaller numbers generated with less code, since you cannot ensure that the shortest code will generate the largest number automatically. – user unknown – 2011-04-12T00:09:24.747It depends on what shelves you have. – kinokijuf – 2011-12-25T11:43:45.470
2Voted to close as not constructive. One year, and still no winning criteria. – user unknown – 2012-01-14T01:36:30.813