Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Robot path problem – SydJS June 2012

A Robot path problem – SydJS June 2012

A Robot path problem helped me realise I still love JavaScript
Project Euler 208 – https://projecteuler.net/problem=208

Filippo Vitale

June 20, 2012
Tweet

More Decks by Filippo Vitale

Other Decks in Programming

Transcript

  1. One-minute Rule "My program takes days to get to the

    answer!" Each problem has been designed according to a "one-minute rule", which means that although it may take several hours to design a successful algorithm with more difficult problems, an efficient implementation will allow a solution to be obtained on a modestly powered computer in less than one minute.
  2. Project Euler - Problem 208 A robot moves in a

    series of one-fifth circular arcs (72°)
  3. Project Euler - Problem 208 A robot moves in a

    series of one-fifth circular arcs (72°) with a free choice of ▪ a clockwise or ▪ an anti-clockwise arc for each step but no turning on the spot.
  4. Project Euler - Problem 208 Given that the robot starts

    facing North: How many journeys of 70 arcs in length can it take that return it, after the final arc, to its starting position? (Any arc may be traversed multiple times) http://projecteuler.net/problem=208
  5. Move left, move right Model: • Move = { L,

    R } • StateI = ( x, y, heading ) StateI
  6. Move left, move right Model: • Move = { L,

    R } • StateI = ( x, y, heading ) • StateII = ( lx, ly, rx, ry ) StateI StateII
  7. Move left, move right How can we rotate a point

    on a plane? http://www.wolframalpha.com/input/?i=%7B100%2C+0%7D+72%C2%B0+rotation
  8. Move left, move right How can we rotate a point

    on a plane? http://www.wolframalpha.com/input/?i=%7B100%2C+0%7D+72%C2%B0+rotation http://www.wolframalpha.com/input/?i=with+center+%7B-50%2C0%7D+rotate+72+deg+%7B50%2C0%7D
  9. ABCDE Model A B C D E 0 1 2

    3 4 heading 0 1 2 3 4
  10. ABCDE Model A B C D E 0 1 2

    3 4 heading counter 0 1 2 3 4 http://jsbin.com/oyifem/edit#preview