From: John W Higgins Date: 2013-03-29T07:47:32+09:00 Subject: Re: Chris Pine Leap Year --089e0168193e82086204d903f049 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Mar 28, 2013 at 3:05 PM, wrote: > Am 28.03.2013 21:48, schrieb John W Higgins: > >> >> >> On Thu, Mar 28, 2013 at 1:17 PM, Phil H. > > wrote: >> >> This one is stumping me because of all the variables needed. Only >> thing >> taught before this challenge was basic branches and loops. This is >> what >> I have so far. >> >> puts 'Leap Year Calculator' >> puts ' ' >> puts 'Enter the starting year.' >> starting_year = gets.chomp >> puts 'Enter the ending year.' >> ending_year = gets.chomp >> >> >> The rest doesn't work at all because if you put something like 2096-2104 >> you would print out 2096, 2100 which is incorrect in two ways >> >> 1) 2100 isn't a leap year >> 2) 2104 should be printed and your second while clause precludes that >> >> You shouldn't be worrying about the starting year as much as you are - >> you need to handle every leap year in the same fashion >> >> So lets try something like this >> >> leap_year = starting_year + starting_year % 4 #set yourself onto a >> possible leap year to start with >> > > does not work: > > Absolutely correct - stupid line by me How about sy = starting_year.to_i then either of leap_year = sy - sy % 4 leap_year = leap_year + 4 unless sy == leap_year or a single line overly cute option leap_year = sy - sy % 4 + 4 * (sy % 4 <=> 0) # I can't think of another way to get the signum function in ruby John --089e0168193e82086204d903f049 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Thu, Mar 28, 2013 at 3:05 PM, <sto.mar@web.de> wrote:
Am 28.03.2013 21:48, schrieb John W Higgins:


On Thu, Mar 28, 2013 at 1:17 PM, Phil H. <lists@ruby-forum.com<= /a>
<mailto:lists@ruby-forum.com>> wrote:

=A0 =A0 This one is stumping me because of all the variables needed. Only t= hing
=A0 =A0 taught before this challenge was basic branches and loops. This is = what
=A0 =A0 I have so far.

=A0 =A0 puts 'Leap Year Calculator'
=A0 =A0 puts ' '
=A0 =A0 puts 'Enter the starting year.'
=A0 =A0 starting_year =3D gets.chomp
=A0 =A0 puts 'Enter the ending year.'
=A0 =A0 ending_year =3D gets.chomp


The rest doesn't work at all because if you put something like 2096-210= 4
you would print out 2096, 2100 which is incorrect in two ways

1) 2100 isn't a leap year
2) 2104 should be printed and your second while clause precludes that

You shouldn't be worrying about the starting year as much as you are -<= br> you need to handle every leap year in the same fashion

So lets try something like this

leap_year =3D starting_year + starting_year % 4 #set yourself onto a
possible leap year to start with

does not work:


Absolutely correct - stupid line by me

How= about

sy =3D starting_year.to_i

then either of

leap_= year =3D sy - sy % 4
leap_year =3D leap_year + 4 unless sy =3D=3D leap_y= ear

or a single line overly cute option

leap_year =3D sy - sy % 4 + = 4 * (sy % 4 <=3D> 0) # I can't think of another way to get the si= gnum function in ruby

John
--089e0168193e82086204d903f049--