Hourglass puzzle: Difference between revisions

(Created page with "{{draft task}} Category:Puzzles Category:Games ;Task Given two hourglass of 4 minutes and 7 minutes, the task is to measure 9 minutes. ;Notes Implemented as a 1-pla...")
 
Line 68:
 
</lang>
 
=={{header|Python}}==
There isn't much of a task description as I write this, but, here goes...
 
<lang python>def hourglass_puzzle():
t4 = 0
while t4 < 10_000:
t7_left = 7 - t4 % 7
if t7_left == 9 - 4:
break
t4 += 4
else:
print('Not found')
return
print(f"""
Turn over both hour glasses at the same time and continue flipping them each
when they individually run down until the 4 hour glass is flipped {t4//4} times,
wherupon the 7 hour glass is immediately placed on its side with {t7_left} hours
of sand in it.
You can measure 9 hours by flipping the 4 hour glass once, then
flipping the remaining sand in the 7 hour glass when the 4 hour glass ends.
""")
hourglass_puzzle()</lang>
 
{{out}}
<pre>Turn over both hour glasses at the same time and continue flipping them each
when they individually run down until the 4 hour glass is flipped 4 times,
wherupon the 7 hour glass is immediately placed on its side with 5 hours
of sand in it.
You can measure 9 hours by flipping the 4 hour glass once, then
flipping the remaining sand in the 7 hour glass when the 4 hour glass ends.</pre>
Anonymous user