http://projecteuler.net/problem=99
Largest exponential
Problem 99
Comparing two numbers written in index form like 211 and 37 is not difficult, as any calculator would confirm that 211 = 2048 37 = 2187.
However, confirming that 632382518061 519432525806 would be much more difficult, as both numbers contain over three million digits.
Using base_exp.txt (right click and 'Save Link/Target As...'), a 22K text file containing one thousand lines with a base/exponent pair on each line, determine which line number has the greatest numerical value.
NOTE: The first two lines in the file represent the numbers in the example given above.
Answer: |
709 |
Racket
#lang racket
(require net/url)
(define port
(get-pure-port
(string->url "http://projecteuler.net/project/base_exp.txt")))
(define max 0)
(define maxlinenum 0)
(let loop ([linenum 1])
(define line (read-line port))
(when (not (eof-object? line))
(displayln linenum)
(define pair (string-split line ","))
(define num (* (string->number (second pair))
(log (string->number (first pair)))))
(when (> num max) (set! max num) (set! maxlinenum linenum))
(loop (add1 linenum))))
(displayln maxlinenum)
'Project Euler' 카테고리의 다른 글
Project Euler solutions in Javelin (0) | 2015.10.13 |
---|---|
Project Euler Problem 66 (0) | 2013.10.27 |
Project Euler Problem 67 (0) | 2013.09.02 |
Project Euler Solutions in Racket (0) | 2012.10.17 |
Project Euler Problem 65 (0) | 2012.10.11 |