I feel like beating the shit out of some punching bag somewhere. Is
this a normal reaction when one is trying to learn to program for the
first time?
I've been programming for over 20 years and I *still* feel like that
sometimes. While I can't say what way is definitively best to deal
with it, I tend to take a five or ten minute walk when I get to
feeling like that. Often, by time that that's done, I've got a fresh
idea for how to approach the problem, or I've thought of something I
may be missing.
I'm stuck in "Flow Control" chapter, specificailly the "Extend Deaf
Grandma" exercise.
I feel like beating the shit out of some punching bag somewhere. Is
this a normal reaction when one is trying to learn to program for the
first time?
Fancy describing the problem, and seeing if someone's got some thoughts on it? Top programming tip - it's amazing how often trying to explain a problem will suddenly make you realise what the answer is. Curious, but true.
You could use until or if (or both). You could make a variable the would
count how many times in a row you said "BYE" to grandma, starting at 0 of
cause, and make it add 1 each times and reset it to 0 if you did not say
"BYE".
Here is an example:
counter = 0
Until (counter == 3)
tell_grandma = gets.chomp
if (tell_grandma == "BYE")
counter += 1
end
end
Just find a way to integrate with your current grandma program
···
2006/3/29, Jan_K <non@none.com>:
Does anyone know where I can find the solutions to the exercises in
this book:
Sometimes I find myself leaving a problem without trying to analyze it,
and then when I come back again, it works. Most of the time, I can't
figure out why... I just scratch my head and think "What did I do
different _this time_?"
The encouraging thing about this is that as you get better, the time
between the head scratching gets longer.
Another resource you can try Ruby on when you get frustrated with Pine
is http://tryruby.hobix.com/
This is interactive and fun, and was written by someone who is
certifiably insane. (He wrote Poignant's Guide.)
I'm stuck in "Flow Control" chapter, specificailly the "Extend Deaf
Grandma" exercise.
I'm stuck trying to do the part to make it do '99 bottles of beer on the
wall' song. I get started in what I hope will work and next thing I know I
have way too many variables and nothing makes sense. I even did something
that made it loop the integer 0. I had to Ctrl-c on that one. <sigh>
Here's what I quit trying at, because no matter how many breaks I took or
whatever, it just wasn't making any sense. :
puts '99 bottles of beer on the wall, 99 bottles of beer,'
'take one down, pass it around,'
'98 bottles of beer on the wall!'
song = '99 bottles of beer on the wall, 99 bottles of beer,
take one down, pass it around,'
song = 99
song2 = '98 bottles of beer on the wall!'
song2 = 99 - 1
last = '1 bottle of beer on the wall'
last = 1
if song2 == last
puts 'Yay!'
else
if song2 - 1
puts
while song == 1
end
endputs '99 bottles of beer on the wall, 99 bottles of beer,'
'take one down, pass it around,'
'98 bottles of beer on the wall!'
song = '99 bottles of beer on the wall, 99 bottles of beer,
take one down, pass it around,'
song = 99
song2 = '98 bottles of beer on the wall!'
song2 = 99 - 1
last = '1 bottle of beer on the wall'
last = 1
if song2 == last
puts 'Yay!'
else
if song2 - 1
puts
while song == 1
end
end
I too wish the author had put examples, say on some pages in the back or
something.
Here's the solution to the Leap Years exercise in the same chapter:
(everything looks OK to me)
···
------------------------------------------------------------
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 - 1
while input < input2.to_i
input = input + 1
if input%4 == 0 || input%400 == 0 && input%100 != 0
puts input.to_s
end
end
---------------------------------------------------------
I might continue posting the solutions for the rest of the book if I
decide to keep on reading.
This way I won't develop any bad habits (because hopefully the
solutions will be scrutinized by at least one other person) and it'll
help anyone else reading the book who gets stuck. I doubt the author
of the book will ever get around to publishing the "official"
solutions.
I feel like beating the shit out of some punching bag somewhere. Is
this a normal reaction when one is trying to learn to program for the
first time?
Yes, that is a typical outward manifestation, or projection, of the
initial programming learning process. And, no, it won't go away. But
there are a few inner thnings on which one needs to focus, as well. To
wit: start learning to "think outside of the box", be prepared for your
mind to "play tricks" on you, and don't fight the fact that virtually
all of the difficulties you will face at first will be "logic errors" in
your own thinking and not some anomally of the computer. Adopting this
attitude will help you maintain calmness and reduce stress. Programming
is mentally hard work. But the reward is well worth it. Plus, we here
in the programming community are available to help you!
"Fix up the ask method. That ask method I showed you was alright,
but I bet you could do better. Try to clean it up by removing the
variables good_answer and answer. Youll have to use return to
exit from the loop. (Well, it will get you out of the whole method,
but it will get you out of the loop in the process.) How do you
like the resulting method? I usually try to avoid using return
(personal preference), but I might make an exception here."
Solution:
···
--------------------------------------------------------------------------------------
def ask question
while true
puts question
reply = gets.chomp.downcase
if reply == 'yes'
return true
elsif reply == 'no'
return false
else
puts 'Please answer "yes" or "no".'
end
end
end
puts 'Hello, and thank you for...'
puts
ask 'Do you like eating tacos?'
ask 'Do you like eating burritos?'
wets_bed = ask 'Do you wet the bed?'
ask 'Do you like eating chimichangas?'
ask 'Do you like eating sopapillas?'
puts 'Just a few more questions...'
ask 'Do you like drinking horchata?'
ask 'Do you like eating flautas?'
puts
puts 'DEBRIEFING:'
puts 'Thank you for...'
puts
puts wets_bed
--------------------------------------------------------------------------------------
Old-school Roman numerals. In the early days of Roman numerals,
the Romans didnt bother with any of this new-fangled subtraction
IX nonsense. No sir, it was straight addition, biggest to littlest -
so 9 was written VIIII, and so on. Write a method that, when
passed an integer between 1 and 3000 (or so), returns a string
containing the proper old-school Roman numeral. In other words,
old_roman_numeral 4 should return 'IIII'. Make sure to test
your method on a bunch of different numbers. Hint: Use the integer
division and modulus methods on page 36.
For reference, these are the values of the letters used:
I = 1 V = 5 X = 10 L = 50
C = 100 D = 500 M = 1000
Modern Roman numerals. Eventually, someone thought it would
be terribly clever if putting a smaller number before a larger one
meant you had to subtract the smaller one. As a result of this
development, you must now suffer. Rewrite your previous method
to return the new-style Roman numerals, so when someone calls
roman_numeral 4, it should return 'IV'.
I'm not quite sure there are solutions. However, as a fellow beginning
programmer, I would enjoy discussing our solutions since I finished that
book only one week ago.
Cheers,
Marco
···
On Thursday, March 30, 2006, at 6:33 AM, Jan_K wrote:
Does anyone know where I can find the solutions to the exercises in
this book:
Hello all. Thanks to all the posters who came before me! You've been
tremendous help. I have a quick question on Chapter 11 - Reading and
Writing, Section 11.3:
I recommend dancing. Reading fiction also often works for me.
kj is right, I've been programming for almost 15 years now and
frustration is a frequent companion.
···
I've been programming for over 20 years and I *still* feel like that
sometimes. While I can't say what way is definitively best to deal
with it, I tend to take a five or ten minute walk when I get to
feeling like that. Often, by time that that's done, I've got a fresh
idea for how to approach the problem, or I've thought of something I
may be missing.
forgot to make it set counter to 0 if it wasn't "BYE", but I'm sure you can
figure that out using else.
···
2006/3/29, Jeppe Jakobsen <jeppe88@gmail.com>:
You could use until or if (or both). You could make a variable the would
count how many times in a row you said "BYE" to grandma, starting at 0 of
cause, and make it add 1 each times and reset it to 0 if you did not say
"BYE".
Here is an example:
counter = 0
Until (counter == 3)
tell_grandma = gets.chomp
if (tell_grandma == "BYE")
counter += 1
end
end
Just find a way to integrate with your current grandma program
2006/3/29, Jan_K <non@none.com>:
> Does anyone know where I can find the solutions to the exercises in
> this book:
>
> http://pine.fm/LearnToProgram/
>
>
> I'm stuck in "Flow Control" chapter, specificailly the "Extend Deaf
> Grandma" exercise.
>
> I feel like beating the shit out of some punching bag somewhere. Is
> this a normal reaction when one is trying to learn to program for the
> first time?
>
> --
> Jan
>
>
I feel like beating the shit out of some punching bag somewhere. Is
this a normal reaction when one is trying to learn to program for the
first time?
I've been programming for over 20 years and I *still* feel like that
sometimes. While I can't say what way is definitively best to deal
with it, I tend to take a five or ten minute walk when I get to
feeling like that. Often, by time that that's done, I've got a fresh
idea for how to approach the problem, or I've thought of something I
may be missing.
Good advice.
See also the Programming and Development episodes of Ward's "EPISODES:
A Pattern Language of Competitive Development" available
at PPR: Pattern Language Titles and the episode failure notes from
his Seattle XP talk: SEAPIG
I feel like beating the shit out of some punching bag somewhere. Is
this a normal reaction when one is trying to learn to program for the
first time?
I've been programming for over 20 years and I *still* feel like that
sometimes. While I can't say what way is definitively best to deal
with it, I tend to take a five or ten minute walk when I get to
feeling like that. Often, by time that that's done, I've got a fresh
idea for how to approach the problem, or I've thought of something I
may be missing.
Well, might I say that he's picked a good language to try out. With
other languages, it would be much, much worse.
A major reason I moved to Ruby is because it vastly reduces (or
sometimes eliminates) frustration while programming. Something [I]
frequently encountered with other languages (C, C++ (esp. Windows
stuff), Java, Perl, Tcl).
I'm stuck trying to do the part to make it do '99 bottles of beer on the
wall' song. I get started in what I hope will work and next thing I know I
have way too many variables and nothing makes sense. I even did something
that made it loop the integer 0. I had to Ctrl-c on that one. <sigh>
Here's what I quit trying at, because no matter how many breaks I took or
whatever, it just wasn't making any sense. :
...
I too wish the author had put examples, say on some pages in the back or
something.
But if you ask this group, you can get interactive answers!
Let's start again with that one. We need a loop counting down from 99. So
first, we need a counter.
beer = 99
Now, we need to count it down.
beer = beer - 1
But we need to do that repeatedly - it goes in a loop.
beer = 99
while (something to end the loop?)
beer = beer - 1
end
How long should we keep looping? We don't want to go past zero. In other
words, we loop while our counter is zero or more.
beer = 99
while beer >= 0
beer = beer - 1
end
OK, now we've got the basic structure of the program - one loop, beer starts
at 99, and decreases until it gets to 0. But there's no output yet.
See how you go putting some flesh on that skeleton, JB - post back when
you're done. (I found learning to program it was better to write than read,
so put aside Herr Froelich's solution and make your own!)