1 ! Copyright (c) 2008 Aaron Schaefer.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: io.encodings.ascii io.files kernel math math.functions
4 math.parser math.vectors project-euler.common sequences
5 sequences.extras splitting ;
8 ! https://projecteuler.net/problem=99
13 ! Comparing two numbers written in index form like 2^11 and 3^7
14 ! is not difficult, as any calculator would confirm that 2^11 =
17 ! However, confirming that 632382^518061 519432^525806 would be
18 ! much more difficult, as both numbers contain over three
21 ! Using base_exp.txt (right click and 'Save Link/Target As...'),
22 ! a 22K text file containing one thousand lines with a
23 ! base/exponent pair on each line, determine which line number
24 ! has the greatest numerical value.
26 ! NOTE: The first two lines in the file represent the numbers in
27 ! the example given above.
33 ! Use logarithms to make the calculations necessary more
38 : source-099 ( -- seq )
39 "resource:extra/project-euler/099/base_exp.txt"
40 ascii file-lines [ "," split [ string>number ] map ] map ;
42 : simplify ( seq -- seq )
43 ! exponent * log(base)
44 flip first2 swap [ log ] map v* ;
46 : solve ( seq -- index )
47 simplify arg-max 1 + ;
51 : euler099 ( -- answer )
54 ! [ euler099 ] 100 ave-time
55 ! 16 ms ave run timen - 1.67 SD (100 trials)