Learn to Program, by Chris Pine

romans.each do |nroman|
number = nroman[0]
letter = nroman[1]

can become:

romans.each do |nroman|
  number, letter = nroman

can become:

romans.each do | (number, letter) |

can become:

···

On Jan 23, 2013, at 09:41 , Martin Alejandro <lists@ruby-forum.com> wrote:

romans.each do | number, letter |

Hi Jan,

Have you been typing his examples into IRB and running them as you go? I
found that technique really useful learning Perl - try variations on the
example code until you understand it. Try reading Chapter 6 again with IRB,
including the mini exercise in the Looping section.

But let's unpack your code while it's here:

Jan K wrote:

Here's what I had when I gave up:

------------------------------------------
input = gets.chomp
number = rand(21)

number2 = 0
keep_count = 0

if keep_count != 3
while
input != 'BYE'
puts 'HUH?! SPEAK UP, SONNY!'
keep_count = 0
input = gets.chomp
while
    input == 'BYE'
puts 'HUH?! SPEAK UP, SONNY!'
number2 = (keep_count + 1)
keep_count = number2
input = gets.chomp
end
end
else
puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'
end
-----------------------------------------

And here's the regular Deaf Grandma solution that I used:

----------------------------------------
input = gets.chomp
number = rand(21)

if
while
input != 'BYE'
puts 'HUH?! SPEAK UP, SONNY!'
input = gets.chomp
end
else
puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'
end
-------------------------------------

When you start dealing with flow control, you'll find that indenting makes a
big difference to how easy it is to read and understand your code. Let's
start by indenting your Grandma code:

if
  while
    input != 'BYE'
    puts 'HUH?! SPEAK UP, SONNY!'
    input = gets.chomp
  end
else
  puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'
end

Note in all Chris' examples, "if" and "while" are always followed by a
condition. If Ruby expects something, but doesn't get it, it'll wait until
the following line. That's what's happening with your if and while. It's the
same as this:

if (while input != 'BYE'
      puts 'HUH?! SPEAK UP, SONNY!'
      input = gets.chomp
    end)
else
....

See, while's condition is "input != 'BYE'", and if's condition is the result
of the whole while loop. The result of a while loop is always nil, so the
condition is always false, so you get 'NO, NOT SINCE'...

That means this section of your program is the same as this:

while input != 'BYE'
  puts 'HUH?! SPEAK UP, SONNY!'
  input = gets.chomp
end
puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'

Indenting and putting the condition on the same line as the "if" or "while"
make the flow of your other program a little easier to see, too.

if keep_count != 3
  while input != 'BYE'
    puts 'HUH?! SPEAK UP, SONNY!'
    keep_count = 0
    input = gets.chomp
    while input == 'BYE'
      puts 'HUH?! SPEAK UP, SONNY!'
      number2 = (keep_count + 1)
      keep_count = number2
      input = gets.chomp
    end
  end
else
  puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'
end

Note you've got a loop inside a loop. To get out of that, the inside loop
has to exit, and then the outside loop, and if you look at their respective
conditions (input == 'BYE') and (input != 'BYE'), that will never happen.

Try going back to the example in the Looping section, and modifying that
little bits at a time. Indent lines inside control structures to help you
see at a glance where they begin and end.

Cheers,
Dave

[snip]

I can't use "Until" because it wasn't covered in the book so far (even
though it seems pretty straightforward what it does). Ditto for "+-"

What was covered so far up until this chapter:

if, else, elsif, while

Here's a very simplified example that I believe uses only what's been
covered up to that point.

last_input = ''
goodbye = 1

while goodbye < 3
  input = gets.chomp

  if input == input.upcase
    puts "NO, NOT SINCE " + (1930 + rand(21)).to_s
  else
    puts "HUH?! SPEAK UP, SONNY!"
  end

  if input == 'BYE' and last_input == 'BYE'
    goodbye = goodbye + 1
  else
    goodbye = 1
  end

  last_input = input
end

···

On 3/29/06, Jan_K <non@none.com> wrote:

--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".

Christian Neukirchen wrote:

Let's start again with that one. We need a loop counting down from 99.

And therefore, we write in Ruby:

99.downto(1) { |bottles| ... }

A good point, Christian, and that syntax is introduced in the very next
chapter after the one we're doing exercises from. It's good to be able to do
things more than one way.

Cheers,
Dave

Jan_K wrote:

···

On Sat, 01 Apr 2006 02:03:13 GMT, "Dave Burt" <dave@burt.id.au> wrote:

Crap, I knew I should have fully tested my code.

<snip>

>> if input%4 == 0 || input%400 == 0 && input%100 != 0
>
>Here's the mistake.
>
>1984 and 2004 are leap years. OK.
>1800 and 1900 are not leap years. Not OK - this program lists them as leap
>years.
>1600 and 2000 are leap years. OK.
>
>In case this info helps, && binds more closely than ||, so what you've got
>is the same as:
>
>if input%4 == 0 || (input%400 == 0 && input%100 != 0)
>
>You should be able to rearrange it to give the correct result for the 1984,
>2004, 1800, 1900, 1600 and 2000.

Yep.

if input%100 != 0 && input%4 == 0 || input%400 == 0

Fix:

-------------------------------------------------------------------------------
puts 'Please enter the starting year'
input = gets.chomp
puts 'Please enter the ending year'
input2 = gets.chomp
puts
puts 'The following are leap years:'

input = input.to_i

while input <= input2.to_i
     if input%100 != 0 && input%4 == 0 || input%400 == 0
      puts input.to_s
    end
  input = input + 1
end
-------------------------------------------------------------------------------

1 line shorter at the expense of readability and performance:

-------------------------------------------------------------------------------
puts 'Please enter the starting year'
input = gets.chomp
puts 'Please enter the ending year'
input2 = gets.chomp
puts
puts 'The following are leap years:'

while input.to_i <= input2.to_i
    if input.to_i%100 != 0 && input.to_i%4 == 0 || input.to_i%400 == 0
  puts input.to_s
    end
input = input.to_i + 1
end
-------------------------------------------------------------------------------

I actually did a little benchmark calculating all the leap years for
the next 100 million years (with output going to nul).

Results:

13:26 minutes for the first one.
14:56 minutes for the second one.

The shorter code was 11.16% slower.

-------------------------------------------------------------------------------
puts 'Please enter the starting year'
input = gets.chomp.to_i # Convert to Integer
puts 'Please enter the ending year'
input2 = gets.chomp.to_i # Convert to Integer
puts
puts 'The following are leap years:'

while input <= input2
     if inputi % 100 != 0 && input % 4 == 0 || input % 400 == 0
   puts input.to_s
     end
input = input + 1
end

Jan_K wrote:

Actually, I just flipped through the rest of the book and it starts to
diverge quite a bit from the online tutorial starting with the next
chapter and has 4 additional new chapters.

Here are the table of contents from the book:
http://pragmaticprogrammer.com/titles/fr_ltp/index.html

So if I have any more questions I'll post the exercise instructions
first.

Good idea; it's sure to avoid further confusion, and I'm sure Mr. Pine wouldn't mind this kind of use of his text.

Thanks for your help so far Dave. I was completely stuck in that Flow
Control chapter and pretty much became content that another attempt at
learning programming has successfully failed (just like the previous
half dozen times). It's amazing how hard it is to grasp incredibly
fucking simple concepts for the first time.

You're more than welcome. I'm chuffed that you say this, and very glad to have helped.

I love teaching programming. I learnt the basics of programming QBasic in a day, back in grade 6, from a friend (probably a little less than the equivalent of what you're up to now). And it is difficult and strange, new vocabulary, "strings", "methods", but it's so useful once you've got it. A lot of repetitive tasks can be reduced to a brain exercise by automating them. (See thread, "Does Ruby simplify our tasks and lives?") And knowing some of these things help you understand computers (and bend them to your every whim bwahahaha... oh, you're still reading?)

But mostly it's just fun.

Cheers,
Dave

···

On Sun, 02 Apr 2006 03:57:21 GMT, Dave Burt <dave@burt.id.au> wrote:

Jeff de Vries wrote:

Restricting to what is covered in chapters 1-10, how about the
following?

Thank you Jeff,
Your Code looks great and I think it is exactly what I'm looking for.

Next I will try to answer your question about the Restriction.

The first ten chapters of the book covers
only a few array methods like each,join,last,length,pop.
no partition, no selection or double assignment.
Futhermore we have if -else,elsif- end, do-end,while-end,puts, gets
(with chomp,downcase),array=,times(3.times do...)
we have basics like numbers and strings ,variables assignment,
comparison methods (==,!=,<,>...),writing own methods (def- end)

In Chapter 11-14 the author talks about:

reading and writing files, creating classes,YAML,Blocks and Procs
and a hint to other learning resources like Programming Ruby or this
mailing-list...

The book is a great starting point with many exercises.
It is great to learn programming. It's explains Basic 'Thinking-Skills'
of
programming and how ruby works.

The author provides only one way to do something. This limitation is
great.
I have no problems with the excercises until chapter 10.
And Chapter 11 should be not so hard to understand (hopefully...)

BTW:
The book is the extended Version of this Tutorial:

http://pine.fm/LearnToProgram/

greetings

Colin

···

--
Posted via http://www.ruby-forum.com/\.

Probably because it makes more sense to people new to Ruby when the code is
in a more traditional format;

i.e.

File.open(file_name, 'w')

Personally the openess of Ruby cased problems for me when I first moved over
(and still does sometimes). I love the fact that you can do things many
different ways in ruby, but when you're trying to learn the language and
you're given 10 different options with 10 different explanations it becomes
much more confusing than only having 1 or 2 ways. :frowning:

···

On 6/13/07, Tm Bo <vineire77@gmail.com> wrote:

Thanks, donald. I don't know why I missed that before.

--
Posted via http://www.ruby-forum.com/\.

You will do well to make notes on File and read/write modes!
The basic implementation of this kind of thing is almost the same in many lanugages, Ruby's is no exception, the style of this comes straight from C .
You will see it in PHP too, and a host of other languages.. (all C's children and relatives.)
Some books fail to document this stuff well for beginners. they either don't want to go there yet, or they forget about it since they assume you know it from other languages.
Mr. Pine just isn't going there in his book. He's focusing on other subjects

···

On Jun 13, 2007, at 4:16 PM, Tm Bo wrote:

Thanks, donald. I don't know why I missed that before.

-- Posted via http://www.ruby-forum.com/\.

Actually, better production code that keeps in line with OO concepts would be...

class Integer
  ROMAN = {
    1 => "I",
    5 => "V",
    10 => "X",
    50 => "L",
    100 => "C",
    500 => "D",
    1000 => "M"
  }

  def roman
    number, roman_string = self, ""
    ROMAN.keys.sort.reverse.each do |key|
      roman_string << (ROMAN[n] * (number/key)
      n %= key
    end
    roman_string
  end
end

#usage
puts 2137.roman
# => "MMCCCXVII"

I'm pretty sure there were better and more thorough examples at
http://www.rubyquiz.com/quiz22.html\.

Todd

···

On Feb 2, 2008 7:47 PM, Todd Benson <caduceass@gmail.com> wrote:

Just for fun. Certainly not great for speed for large numbers, but the
integer max was low so...

H = Hash[*(([1,5,10,50,100,500,1000].zip %w|I V X L C D M|).flatten)]
def roman(n, s="")
  H.keys.sort.reverse.each do |k|
    s << (H[k] * (n / k))
    n %= k
  end
  s
end
puts roman(ARGV[0].to_i)

The usage would simply be "ruby <filename>.rb <number>"

I'm sure someone could come up with a one-liner, though.

<snip>

When you start dealing with flow control, you'll find that indenting makes a
big difference to how easy it is to read and understand your code.

It is indented. Must be your client.

Try this:

Tools --> Options --> Read tab

Check "Read all messages in plain text"

<snip>

Note you've got a loop inside a loop. To get out of that, the inside loop
has to exit, and then the outside loop, and if you look at their respective
conditions (input == 'BYE') and (input != 'BYE'), that will never happen.

<snip>

The problem was that I didn't realize that I messed up the first
Grandma program (which reinforced some misconceptions because the
program was working ok). Then I sort of got this idea that I had to
use a loop inside a loop and really couldn't get out of that box.

Everything is obvious now.

Agony of defeat, ecstacy of success.

Anyway, here's the final program:

(hopefully I don't have any superfluous code this time around)

···

On Thu, 30 Mar 2006 10:17:55 GMT, "Dave Burt" <dave@burt.id.au> wrote:

-----------------------------------------------------------------
number = rand(21)
number2 = 0
keep_count = 0

while keep_count != 3
  input = gets.chomp
    if input != 'BYE'
      keep_count = 0
      puts 'HUH?! SPEAK UP, SONNY!'
    else
      number2 = (keep_count + 1)
      keep_count = number2
        if keep_count != 3
          puts 'HUH?! SPEAK UP, SONNY!'
        end
    end
end

puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'
----------------------------------------------------------------

--
Jan

I'm not really understanding what last_input is exactly doing. Looks
like nothing.

This works without any problems:

goodbye = 1

while goodbye < 4
  input = gets.chomp

  if input == input.upcase
    puts "NO, NOT SINCE " + (1930 + rand(21)).to_s
  else
    puts "HUH?! SPEAK UP, SONNY!"
  end

  if input == 'BYE'
    goodbye = goodbye + 1
  else
    goodbye = 1
  end
end

···

On Sat, 1 Apr 2006 02:08:40 +0900, "Bill Guindon" <agorilla@gmail.com> wrote:

On 3/29/06, Jan_K <non@none.com> wrote:
[snip]

I can't use "Until" because it wasn't covered in the book so far (even
though it seems pretty straightforward what it does). Ditto for "+-"

What was covered so far up until this chapter:

if, else, elsif, while

Here's a very simplified example that I believe uses only what's been
covered up to that point.

last_input = ''
goodbye = 1

while goodbye < 3
input = gets.chomp

if input == input.upcase
   puts "NO, NOT SINCE " + (1930 + rand(21)).to_s
else
   puts "HUH?! SPEAK UP, SONNY!"
end

if input == 'BYE' and last_input == 'BYE'
   goodbye = goodbye + 1
else
   goodbye = 1
end

last_input = input
end

Hello!

To sum the digits of an Integer I have got

class Integer
   def sum_digits()
     sum = 0
     n = self
     begin sum += n % 10; n /= 10 end while n > 0
     sum
   end
end

Is there a more Ruby Way to do this? The above method smells of Java, doesn't it?

Thanks, Marcus

Cool.

···

On 1 Apr 2006 07:32:50 -0800, jzakiya@mail.com wrote:

-------------------------------------------------------------------------------
puts 'Please enter the starting year'
input = gets.chomp.to_i # Convert to Integer
puts 'Please enter the ending year'
input2 = gets.chomp.to_i # Convert to Integer
puts
puts 'The following are leap years:'

while input <= input2
    if inputi % 100 != 0 && input % 4 == 0 || input % 400 == 0
  puts input.to_s
    end
input = input + 1
end

For interest, before I bought the book I did this exercise for the
online tuorial. That was before I knew about recursives, here is what
I came up with... it works, but it's not pretty

words_array = []
puts 'Please enter any word'
word = gets.chomp

while word != ''
  words_array.push word
  puts 'Great, please enter another word'
  word = gets.chomp
end

sorted_array = []

words_array.each do |word|
  if word.to_s.downcase > sorted_array.last.to_s.downcase
    #add word to the end of sorted_array
    sorted_array.push word

  else
    index = (sorted_array.length) - 1
    initial_number = index
    temp_array = []

    #check word against next word in sorted_array and repeat
    while word.to_s.downcase < sorted_array[index].to_s.downcase
      #add the sorted_array to a temp_array up to that point
      temp_array[index] = sorted_array[index]
      #erase words in sorted_array up to that point
      sorted_array.pop
      index = index - 1
    end

    #add the word to sorted_array
    sorted_array.push word

    #add one by one the words from temp_array to sorted_array
    while index < initial_number
      sorted_array.push temp_array[index + 1]
      index = index + 1
    end
  end
end

puts sorted_array

···

--
Posted via http://www.ruby-forum.com/.

gsub('number', 'n') on that code...and there's a missing parenthesis
")" number/key line

Yeah, yeah

That's what I get for not using cut and paste :slight_smile:

Todd

···

On Feb 2, 2008 8:49 PM, Todd Benson <caduceass@gmail.com> wrote:

Actually, better production code that keeps in line with OO concepts would be...

class Integer
  ROMAN = {
    1 => "I",
    5 => "V",
    10 => "X",
    50 => "L",
    100 => "C",
    500 => "D",
    1000 => "M"
  }

  def roman
    number, roman_string = self, ""
    ROMAN.keys.sort.reverse.each do |key|
      roman_string << (ROMAN[n] * (number/key)
      n %= key
    end
    roman_string
  end
end

#usage
puts 2137.roman
# => "MMCCCXVII"

I'm pretty sure there were better and more thorough examples at
http://www.rubyquiz.com/quiz22.html\.

Jan K wrote:

It is indented. Must be your client.

Wow, my client's not displaying tabs. That really kinda sucks. Thanks for
the heads-up!

The problem was that I didn't realize that I messed up the first
Grandma program (which reinforced some misconceptions because the
program was working ok). Then I sort of got this idea that I had to
use a loop inside a loop and really couldn't get out of that box.

Everything is obvious now.

Agony of defeat, ecstacy of success.

Yay!

Once you've got Flow Control, now you can write programs to do real-life
useful tasks!

Anyway, here's the final program:

(hopefully I don't have any superfluous code this time around)

That might be a little much to expect this early in the game :slight_smile:

-----------------------------------------------------------------
number = rand(21)
number2 = 0
keep_count = 0

while keep_count != 3
input = gets.chomp
  if input != 'BYE'
   keep_count = 0
   puts 'HUH?! SPEAK UP, SONNY!'
  else
   number2 = (keep_count + 1)
   keep_count = number2
    if keep_count != 3
     puts 'HUH?! SPEAK UP, SONNY!'
    end
  end
end

puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'
-----------------------------------------------------------------

The line is "number2 = 0" is superfluous, because the first thing you do is
assign to it, but it does serve to make it obvious to the programmer the
variable exists.

If it was my program, though, I'd drop the variables "number" and "number2",
and just use the formula directly place - they're only used once each. Like
this:
    keep_count = keep_count + 1
And like this:
    puts 'NO, NOT SINCE ' + (1930 + rand(21)).to_s + '!'

Note you don't need parentheses around the formula on the right-hand side of
an assignment: + is done before =.

Finally, I prefer not to use the negative "if x != y then foo else bar"
because I find easier to understand "if x == y then bar else foo". Another
alternative is to use "unless", which Chris seems not to have introduced in
Chapter 6, but it means "if not". Same for while - "while keep_count != 3"
is the same as "until keep_count == 3".

So here are my changes to your program all together:

keep_count = 0
until keep_count == 3
  input = gets.chomp
  if input == 'BYE'
    keep_count = keep_count + 1
    unless keep_count == 3
      puts 'HUH?! SPEAK UP, SONNY!'
    end
  else
    keep_count = 0
    puts 'HUH?! SPEAK UP, SONNY!'
  end
end
puts 'NO, NOT SINCE ' + (1930 + number).to_s + '!'

But, my understanding of the question must be different to yours. I
understand the original should behave like this:

Hello Grandma

HUH?! SPEAK UP, SONNY!

HELLO GRANDMA

NO, NOT SINCE 1938!

WHAT HASN'T BEEN SINCE 1938?

NO, NOT SINCE 1945!

BYE

BYE, BYE

And the 3-times one should be something like:

Hello Grandma

HUH?! SPEAK UP, SONNY!

HELLO GRANDMA

NO, NOT SINCE 1938!

BYE

HUH?! SPEAK UP, SONNY!

BYE

HUH?! SPEAK UP, SONNY!

BYE

BYE, BYE

I've written my solutions to these after some whitespace at the end of this
message.

Cheers,
Dave

# Deaf Grandma
input = gets.chomp
until input == "BYE"
  if input == input.upcase
    puts "NO, NOT SINCE " + (1930 + rand(21)).to_s + "!"
  else
    puts "HUH!? SPEAK UP, SONNY!"
  end
  input = gets.chomp
end
puts "BYE, BYE"

# Extra Deaf Grandma
byes = 0
input = gets.chomp
until byes == 3
  if input == "BYE"
    byes = byes + 1
  else
    byes = 0
  end
  if input == input.upcase
    puts "NO, NOT SINCE " + (1930 + rand(21)).to_s + "!"
  else
    puts "HUH!? SPEAK UP, SONNY!"
  end
  input = gets.chomp
end
puts "BYE, BYE"

>[snip]
>> I can't use "Until" because it wasn't covered in the book so far (even
>> though it seems pretty straightforward what it does). Ditto for "+-"
>>
>> What was covered so far up until this chapter:
>>
>> if, else, elsif, while
>>
>
>Here's a very simplified example that I believe uses only what's been
>covered up to that point.
>
>last_input = ''
>goodbye = 1
>
>while goodbye < 3
> input = gets.chomp
>
> if input == input.upcase
> puts "NO, NOT SINCE " + (1930 + rand(21)).to_s
> else
> puts "HUH?! SPEAK UP, SONNY!"
> end
>
> if input == 'BYE' and last_input == 'BYE'
> goodbye = goodbye + 1
> else
> goodbye = 1
> end
>
> last_input = input
>end

I'm not really understanding what last_input is exactly doing. Looks
like nothing.

I may be reading ahead of you, but it doesn't look like it.
http://pine.fm/LearnToProgram/?Chapter=06

It's there to honor this spec:
"Change your previous program so that you have to shout BYE three
times in a row. Make sure to test your program: if you shout BYE three
times, but not in a row, you should still be talking to grandma."

It's making sure that it exits when you say:
"BYE", "BYE", "BYE"

but it won't exit if you say:
"BYE", "DOG", "BYE", "BYE"

If that's what you typed, on the third input, last_input would be
"DOG", so 'goodbye' would get reset to '1'.

···

On 3/31/06, Jan_K <non@none.com> wrote:

On Sat, 1 Apr 2006 02:08:40 +0900, "Bill Guindon" <agorilla@gmail.com> > wrote:
>On 3/29/06, Jan_K <non@none.com> wrote:

This works without any problems:

goodbye = 1

while goodbye < 4
  input = gets.chomp

  if input == input.upcase
    puts "NO, NOT SINCE " + (1930 + rand(21)).to_s
  else
    puts "HUH?! SPEAK UP, SONNY!"
  end

  if input == 'BYE'
    goodbye = goodbye + 1
  else
    goodbye = 1
  end
end

--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".

Hello!

To sum the digits of an Integer I have got

class Integer
  def sum_digits()
    sum = 0
    n = self
    begin sum += n % 10; n /= 10 end while n > 0
    sum
  end
end

Is there a more Ruby Way to do this? The above method smells of Java, doesn't it?

Here is what I thought of when reading this:

>> class Integer
>> def sum_digits
>> to_s.split("").inject(0) { |sum, n| sum + n.to_i }
>> end
>> end
=> nil
>> 1234.sum_digits
=> 10

Hope that helps.

James Edward Gray II

···

On Apr 1, 2006, at 7:22 AM, Marcus Lunzenauer wrote:

I'm having some issues modifying the Civ continent example from ch. 10
to account for coordinates that are outside the array. I added the
following line:

if ((y <= 10 && y > 0) && (x <= 10 && x > 0))

before...

  # So, first we count this tile...
  size = 1
  world[y][x] = 'counted land'

    # ...then we count all of the
    # neighboring eigth tiles (and,
    # of course, their neighbors via recursion)
    size = size + continent_size(world, x-1, y-1) #4,4
    size = size + continent_size(world, x , y-1) #5,4
    size = size + continent_size(world, x+1, y-1) #6,4
    size = size + continent_size(world, x-1, y ) #4,5
    size = size + continent_size(world, x+1, y ) #6,5
    size = size + continent_size(world, x-1, y+1) #4,6
    size = size + continent_size(world, x , y+1) #5,6
    size = size + continent_size(world, x+1, y+1) #6,6
    size
end

As a result, I get the following error:

TypeError: nil can't be coerced into Fixnum

method + in civilization.rb at line 35
method continent_size in civilization.rb at line 35
method continent_size in civilization.rb at line 35
method continent_size in civilization.rb at line 36
method continent_size in civilization.rb at line 35
method continent_size in civilization.rb at line 40
method continent_size in civilization.rb at line 39
method continent_size in civilization.rb at line 41
method continent_size in civilization.rb at line 39
method continent_size in civilization.rb at line 41
method continent_size in civilization.rb at line 39
method continent_size in civilization.rb at line 36
method continent_size in civilization.rb at line 35
at top level in civilization.rb at line 48

This error appears regardless of whether the arguments I pass are in 5,5
(as in the example Chris Pine wrote out) or something like 10,10 (which
is on the edge of the 'continent').

Is that the right conditional statement? Could it be in the wrong place
in the method?

···

--
Posted via http://www.ruby-forum.com/.