SHARE
TWEET

ShortestSequenceOfOperation

g-stoyanov Jun 2nd, 2013 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Task 10*
  3.  * We are given numbers N and M and the following operations:
  4.  * N = N+1
  5.  * N = N+2
  6.  * N = N*2
  7.  * Write a program that finds the shortest sequence of operations
  8.  * from the list above that starts from N and finishes in M.
  9.  * Hint: use a queue.
  10.  * Example: N = 5, M = 16
  11.  * Sequence: 5 ---> 6 ---> 8 ---> 16
  12.  */
  13.  
  14. namespace Task10Version2ShortestSequenceOfOperation.Common
  15. {
  16.     class ShortestSequenceOfOperation
  17.     {
  18.         static void Main()
  19.         {
  20.             ShortestPathFinder pathFinder = new ShortestPathFinder(5, 16);
  21.             pathFinder.PrintShortestPaths();
  22.             System.Console.WriteLine();
  23.             pathFinder = new ShortestPathFinder(0, 26);
  24.             pathFinder.PrintShortestPaths();
  25.             System.Console.WriteLine();
  26.             pathFinder = new ShortestPathFinder(-5, 26);
  27.             pathFinder.PrintShortestPaths();
  28.             System.Console.WriteLine();
  29.             pathFinder = new ShortestPathFinder(-8, 26);
  30.             pathFinder.PrintShortestPaths();
  31.             System.Console.WriteLine();
  32.             pathFinder = new ShortestPathFinder(-13, 0);
  33.             pathFinder.PrintShortestPaths();
  34.         }
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top