I worked on euler 8 which was to find the string of 13 numbers in a giant list of given numbers that had the greatest product. I made a function that processed the data from a copy-pasted file into an array of individual numbers. I did it in a one-liner for the hell of it:
def parse_info(filestring)
#takes a file and parses a large string of integers into an array of integers
integer_list = []
# parse the input into an array of individual integers
File.readlines(filestring).each { |line| line[0...-1].split("").each {|char| integer_list << char.to_i}}
return integer_list
end
I wrote a test or two at the end, but rspec doesn't lend itself very well to testing non-objects and making an object for this seemed kinda silly.
last modified | size | ||
euler_8.rb | Wed Dec 04 2024 07:13 pm | 1.0K | |
euler_8_spec.rb | Wed Dec 04 2024 07:13 pm | 342B |