Jim's
Tutorials

Fall 2018
course
site

somewhat spaghetti code - but I'm not sure why I dont have access to integer_list. This is the terminal output of my error:

>> ➜  ruby git:(master) ✗ ruby euler_11.rb
euler_11.rb:43:in `block (3 levels) in greatest_product_four': undefined method `[]' for nil:NilClass (NoMethodError)
    from euler_11.rb:41:in `times'
    from euler_11.rb:41:in `block (2 levels) in greatest_product_four'
    from euler_11.rb:38:in `each'
    from euler_11.rb:38:in `each_with_index'
    from euler_11.rb:38:in `block in greatest_product_four'
    from euler_11.rb:33:in `each'
    from euler_11.rb:33:in `greatest_product_four'
    from euler_11.rb:65:in `<main>'

re-did the code, did some debugging seems to be mostly working but apparently it's only handling for the first offset. The loop seems to be checking every i when i print through it so I'm not quite sure. My test is testing a grid with a bunch of 2's and 2 4's on each axis like so:

02 02 02 02 02 02 02 02
02 02 02 02 02 02 02 02
02 02 02 04 02 02 02 02
02 02 02 04 02 02 02 02
02 04 02 02 02 04 02 02
02 02 02 02 02 02 02 02
02 02 02 02 02 02 02 02
02 02 02 02 02 02 02 02

output from running the test:

Failures:

  1) Euler_11#grid_search finds the greatest product 4 in a row in any direction
     Failure/Error: expect(example.grid_search).to eq(16)

       expected: 64
            got: 32

       (compared using ==)
     # ./spec/euler_11_spec.rb:8:in `block (3 levels) in <top (required)>'

Finished in 6.75 seconds (files took 0.4908 seconds to load)

attachments [paper clip]

  last modified size
TXT euler_11.rb Fri Apr 26 2024 10:40 am 3.8K
TXT euler_11_spec.rb Fri Apr 26 2024 10:40 am 284B
TXT euler_11_test_input.txt Fri Apr 26 2024 10:40 am 192B
TXT euler_11_text.txt Fri Apr 26 2024 10:40 am 1.2K