Find connection between two numbers

Spread the word!

Inspired by Calculator: The Game, after some seconds of frustration during the attempt to solve its levels and after being humiliated by the superior intelligence of my girlfriend I decided to increase the self-esteem of my brain and develop a simple algorithm to solve this game for me. The rules are simple: you have a starting number, some operations you can use and the final number you have to get within a given amount of steps.

This PDF describes how to the algorithm works and the php code that implement it. To show you the result I embedded here an example directly using the php code. In this example you can set the start and end value, and the script will find the shortest path (if exists) to connect them by using the following operations: -1, *5, mirror (e.g. from 123 to 321), sum up digits, right shift (e.g. from 123 to 312), invert sign. I intentionally set the maximum number of steps to 7.

You can try the sample script at this address: http://samplecodes.altervista.org/sequence.php

Be the first to comment

Leave a Reply

Your email address will not be published.


*