Advertisement
g-stoyanov

ShortestSequenceOfOperation

Jun 2nd, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement