Skip to content

alexmaraval/calvin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

calvin

Calvin and the magic wand.

This is a puzzle I found and I set to solve using mathematics for the first base cases and then coding up two versions of a general solution based on a recurrence relation found. See the PDF file for more details.

Problem

Calvin has to cross several signals when he walks from his home to school. Each of these signalsoperate independently. They alternate every 80 seconds between green light and red light. Ateach signal, there is a counter display that tells him how long it will be before the currentsignal light changes. Calvin has a magic wand which lets him turn a signal from red to greeninstantaneously. However, this wand comes with limited battery life, so he can use it only for aspecified number of times. (a) If the total number of signals is 2 and Calvin can use his magic wand only once, then whatis the expected waiting time at the signals when Calvin optimally walks from his home to school? (b) What if the number of signals is 3 and Calvin can use his magic wand only once? (c) Can you write a script (in any programming language of your choice) that takes as inputsthe number of signals and the number of times Calvin can use his magic wand, and outputs the expected waiting time?

About

Calvin and the magic wand Puzzle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages