2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
def powers(m)
|
||||
return enum_for(__method__, m) unless block_given?
|
||||
|
||||
n = 0
|
||||
loop { yield n ** m; n += 1 }
|
||||
0.step{|n| yield n**m}
|
||||
end
|
||||
|
||||
def squares_without_cubes
|
||||
|
|
|
|||
|
|
@ -2,17 +2,15 @@
|
|||
|
||||
def powers(m)
|
||||
return enum_for(__method__, m) unless block_given?
|
||||
|
||||
n = 0
|
||||
loop { yield n ** m; n += 1 }
|
||||
0.step{|n| yield n**m}
|
||||
end
|
||||
|
||||
def squares_without_cubes
|
||||
return enum_for(__method__) unless block_given?
|
||||
|
||||
cubes = powers(3)
|
||||
cubes = powers(3) #no block, so this is the first generator
|
||||
c = cubes.next
|
||||
squares = powers(2)
|
||||
squares = powers(2) # second generator
|
||||
loop do
|
||||
s = squares.next
|
||||
c = cubes.next while c < s
|
||||
|
|
@ -20,6 +18,6 @@ def squares_without_cubes
|
|||
end
|
||||
end
|
||||
|
||||
answer = squares_without_cubes
|
||||
answer = squares_without_cubes # third generator
|
||||
20.times { answer.next }
|
||||
p 10.times.map { answer.next }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue