Jim's
Tutorials

Fall 2018
course
site

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.

attachments [paper clip]

  last modified size
TXT euler_8.rb Fri Apr 19 2024 10:04 am 1.0K
TXT euler_8_spec.rb Fri Apr 19 2024 10:04 am 342B