+ 6

Challenge :: The twelve days of Christmas

"On the first day of Christmas my True Love sent to me: A Partridge in a Pear Tree On the second day of Christmas my True Love sent to me: Two Turtle Doves and a Partridge in a Pear Tree..." Last Christmas John has received many gifts from his True Love. But his home is running out of space because of some doves and pipers. This year he can only accept a certain number of presents. Calculate the number of days for which John can receive presents. Input: The number of presents John can accept. Output: "John can receive presents for <solution> day(s)." Examples (but feel free to implement more creative solutions): Input: 1 Output: John can receive presents for 1 day(s). Input: 10 Output: John can receive presents for 3 day(s). Input: 100 Output: John can receive presents for 8 day(s). Input: 1000 Output: John can receive presents for 12 day(s). Further read: https://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song)

19th Sep 2017, 6:48 AM
László Ozsvárt
László Ozsvárt - avatar
7 Answers
+ 13
Ok, got it :) https://code.sololearn.com/crn904kvaseE/?ref=app EDIT: Changed it a bit... 🎄🎁
18th Sep 2017, 7:51 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 10
So to be perfectly clear - on the first day it's just a partridge, on the second day it's two turtle doves, a partridge and the partridge from the other day and so on incrementally? 1: 1 2: 1 + (2 + 1) = 4 3: 1 + (2 + 1) + (3 + 2 +1) = 10 . . ?
18th Sep 2017, 6:32 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
here it is... 🐍 I think in the Challenge description there is a typo: if input is 1000 the output should be 18, not 12... https://code.sololearn.com/cH1xZyad4bcK/?ref=app
18th Sep 2017, 8:20 PM
m abrate
m abrate - avatar
+ 4
Hahahaha....true love!!!...hahahaha
20th Sep 2017, 4:21 AM
iephte
iephte - avatar
18th Sep 2017, 7:57 PM
sayan chandra
sayan chandra - avatar
+ 1
@Kuba: Yes, exactly :)
19th Sep 2017, 5:47 AM
László Ozsvárt
László Ozsvárt - avatar
+ 1
@m abrate: If John kept receiving presents after the 12th day then yes, 18 would be the answer. But his True Love can afford to buy presents only for 12 days :)
19th Sep 2017, 5:52 AM
László Ozsvárt
László Ozsvárt - avatar