Skip to content

Commit

Permalink
Improove Peter's Smokes
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoliveira committed Sep 10, 2015
1 parent a50cfec commit ee69fc0
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions peter_cigarrets/peter_cigarrets.rb
@@ -1,36 +1,18 @@
class PetterCigarrets

def calcule(cigarrets, min_butts)
smoked = smoke(cigarrets - 1, 1, min_butts, 1)
smoked = smoke(cigarrets,min_butts, 0, 0)
return smoked
end

def smoke(cigarret, butts, minbutts, smoked_qtdy)

private
def smoke(cigarret, minbutts, butts, smoked)
if butts > minbutts
cigarret += 1; butts = 1
end
cigarret += 1; butts = 1
end

return smoked_qtdy if cigarret == 0
return smoked if cigarret == 0

smoke(cigarret - 1, butts +1, minbutts, smoked_qtdy + 1)
smoke(cigarret - 1, minbutts, butts + 1, smoked + 1)
end

# def calcule(cigarrets, min_butts)
# c = cigarrets
# butts = 0
# smoked = 0
#
# while c > 0
# c -= 1
# butts += 1
# if butts > min_butts
# c += 1
# butts = 1
# end
# smoked += 1
# end
#
# return smoked
# end

end

0 comments on commit ee69fc0

Please sign in to comment.