Created
February 6, 2013 02:10
-
-
Save joeletizia/4719640 to your computer and use it in GitHub Desktop.
A solution (at least I think it's right...) to http://challenge.signpost.com/leveltwo The Ransom Glad you've made it this far, intrepid friend of Max. To tell you a little about ourselves, our goal is to end winter in Chicago. We've read our Ries and plan to start small, with an MVP. We currently have the resources to build a structure covering …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
def adj_sum(multi,x,y) | |
sum = multi[x][y].to_i | |
if x > 0 | |
sum += multi[x-1][y].to_i | |
end | |
if x < 999 | |
sum += multi[x+1][y].to_i | |
end | |
if y > 0 | |
sum += multi[x][y-1].to_i | |
end | |
if y < 17 | |
sum += multi[x][y+1].to_i | |
end | |
sum | |
end | |
data = open("http://challenge.signpost.com/static/density.txt") | |
lines = Array.new | |
data.each_line {|line| lines << line.split(' ')} | |
max = 0 | |
line_num = 0 | |
for k in (0...1000) | |
for j in (0...18) | |
total_people = adj_sum(lines,k,j) | |
max = total_people unless max > total_people | |
end | |
end | |
puts "max is #{max}" | |
Wow, didn't notice you wrote here, Seth. Thanks.
I figured I was right. Thanks for the help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I arrived at the same result using JavaScript--and was told the answer was
Wrong
.You should be able to run this from the console in Chrome Developer Tools on the density page: