From: dblack@... Date: 2006-09-25T01:15:18+09:00 Subject: Re: Help w/ Codegolf Total Triangles- reading input Hi -- On Mon, 25 Sep 2006, Devin Mullins wrote: > Drew Olson wrote: >> Work backwards row by row. In each row, compare the current element with >> the next, and whichever ever is larger, add this number to the element in >> the same index in the next highest row. Eventually, the value in a[0][0] >> will be the largest path...does this makes sense? Is it an effective >> strategy? > Yeah, that does seem like it'll work. I never thought of it that way. > > Think of the forwards algorithm, too. Then determine if the code you write > with the backwards is 8 bytes shorter (to make up for reverse_each vs each). > (I'll have to look at it, myself. :P) > > One more hint: You probably don't need to waste your time with map. Consider: > a=readlines.each{|i|i.split(" ").each{|j|j=j.to_i}} That just assigns the lines you've read in, unchanged, to a. In the outer each, you split lines and send the results, before you discard them, to the inner each -- where you reuse the identifier j, and then throw its new value away. Meanwhile, all a cares about is the return value of readlines.each, which is its receiver. I think maybe map is indeed called for :-) David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org