From: MonkeeSage Date: 2006-09-24T21:50:17+09:00 Subject: Re: Help w/ Codegolf Total Triangles- reading input Drew Olson wrote: > GAH! Why is it printing the ascii character value? Do I have a logic > flaw in the way I'm reading the input? Is there a better way to read the > input? Should I just tear my hair out? Well firstly, because as others have mentioned, you were using #each, so you were getting an array populated with strings: ["1", "1 2", "1 3 2", "1 4 2 1"] ^ ...and the 1-index of the 1-item of the array is a space (" ") -- ascii ordinal 32. But why doesn't ruby give you the space -- why the ordinal? Because in 1.8, indexing a string by a single integer gives you the ascii ordinal for that character of the string (this changed in 1.9, now it gives you the character and you have to explicitly use #ord to get the ordinal). So, 'a'[0] => 97. If you ever need to get around that, just make the indexer into a range: 'a'[0,1] => a, 'a'[0..0] => a. Regards, Jordan