-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProblem99.rb
More file actions
executable file
·13 lines (8 loc) · 843 Bytes
/
Problem99.rb
File metadata and controls
executable file
·13 lines (8 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
# 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.
require 'mathn'
number_pairs = File.open("base_exp.txt","r"){|file| file.read}.split("\n").collect{|line| line.split(",")}.collect{|pair| [pair[0].to_i, pair[1].to_i]}
values = number_pairs.collect{|pair| Math.log(pair[0])*pair[1]}
puts values.index(values.max)