'''
April 2018 Puzzler

To reward his son for good behavior, Isaac gave his son quarters for N
consecutive days.
On the first day, he gave him 1 quarter and then 1/7th of the quarters that
remained. On the second day, he gave him 2 quarters and then 1/7th of the
quarters that remained. On the third day, he gave him 3 quarters and then
1/7th of the quarters that remained. This continued until the Nth day, when
he gave his son N quarters and ran out of quarters.
How many total quarters did Isaac give his son and over how many days did
this occur?
'''

from __future__ import print_function   #so this will work with Py 2.7

def doDay(day):
    '''
    Each day Isaac give his son that day number of quarters plus
    exactly 1/7 of the remaining quarters (remaining quarters must
    be evenly divisible by 7).
    '''
    global remaining

    given = day
    remaining -= day
    if remaining % 7:   
        remaining = 0               #If not divible by 7, abort
    else:
        given += remaining//7
        remaining -= remaining//7
        #print("On day", day, "gave:", given)
    return

def doDays(total):
    '''
    Cycle through multiple days of giving coins
    '''
    global remaining

    remaining = total
    day = 1
    while remaining > 0:
        doDay(day)
        day += 1
        if remaining == day:        #Amount left = day, we are done
            print("Number of days:",day, "\nTotal number of quarters:", total)
    

if __name__ == '__main__':
    
    remaining = 0

    for n in range(1000000):
        doDays(n)
        #print(n)