From: jake kaiden Date: 2011-10-22T21:12:59+09:00 Subject: Re: power of 2 code hi Ray, hmmm, a couple of things - > heres my code; > > puts "Enter a maximum value: " > number =gets.chomp.to_i > high =number ### why this? > while number < 10_000 ### and why this? > number *= 2 ### this multiplies, doesn't raise exponentially > end > puts high.to_s + " is the highest " + \ > "power of 2 less than " + number.to_s maybe something like this is what you're looking for... ####### puts "Enter maximum value:" max = gets.chomp.to_i puts n = 0 while 2 ** (n + 1) < max n += 1 end puts "2^#{n} = #{2 ** n} is the highest power of 2 less than #{max}" ####### here, the while loop increases the value of the exponent `n` by 1 unless the result is greater than `max`. Enter maximum value: 124123 => 2^16 = 65536 is the highest power of 2 less than 124123 hth, j -- Posted via http://www.ruby-forum.com/.