Thread: algorithm help--

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    221

    algorithm help--

    The question is, given an n x n checker board, and a cost function, fund the maximum value to move the checker from the bottom row to the top row. only stipulation is when you move up, you can only go to the square above you or diagnal (sp) left or right.

    the cost function will basically return the cost and the inputs will be ur current row and col and the next row and col.

    obviously, im not asking for the answer, but i am asking for help on where to start.
    thanks

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    well first try finding a pattern that if moved in these series of steps you will always endup with the biggest cost....it is fairly simple if you think about it. Once you have that then its a matter of coding it.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    i dont mean to sound rude, but thats kinda too vauge for me
    Last edited by revelation437; 03-06-2004 at 02:39 PM.

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    sorry...but thats the toughest art of "algorythm development" - try it your self with a pen and paper, or a board of you have one. First find out which path gives the lowest cost - straight up. And then start finding other paths while counting. Develop a mathematical expression and you're done The pattern is real simple.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Post what you have so far. Also, whenever you have to write a program from a specification, it helps to do a 'domain analysis' of the problem first. This might state:

    1) the program specification itself.
    2) the specification, in your own words.
    3) what you understand about the problem.
    4) what you don't understand about the problem.
    5) research TODO's
    6) extensibility/enhancement considerations.

    That will help solidify you plan of action. Throughout the development process you can add/revise to it as needed, of course. Then start by writing the program out in psuedocode - preferably using a 'top-down' approach. Next, 'stub out' the program, ie: put all of the functions in place but just have them print entry/exit messages and return dummy values. Finally, start adding the code, making sure to recompile the program often in order to tackle syntax/logical errors in managable pieces. The point is, you should always use a systematic approach when you're designing/implementing a program. It almost always turns out better than if you had just 'jumped right in'.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    its in java, sorry guys. this is for a java class im taking
    i ask here other than anywhere else cause its been proven that people here know their $$$$

    Code:
    class DorinsMethods{
      //c1 < c2 pts wise...
      public static int cost(int n,int c1,int r1,int c2,int r2)
          throws IllegalArgumentException {
        //if(c1 < 1 || c1 > 10 || c2 < 1 || c2 > 10 ||
        //   r1 < 1 || r1 > 10 || r2 < 1 || r2 > 10)
        //  return 0;
        return n + (r2-r1);
      }
    }
    
    public class Checker{
      static int bounds = 0;
      public static void main(String args[]){
    
        //error checking
        try{
          bounds = Integer.parseInt(args[0]);
        }
        catch (Exception e) {
          System.out.println("Usage is: SlidingCheckers <number>");
          System.exit(1);
        }
        //end error checking
        System.out.println(DorinsMethods.cost(4, 3, 4, 4, 5));
        bestof(bounds, bounds-2);
      }
    
      public static int solve(int row, int col) {
        
      }
    
      public static int max(int arg1, int arg2, int arg3) {
        int temp = Math.max(arg1, arg2);
        return Math.max(temp, arg3);
      }
      
      public static int bettermove(int row, int col){
        int answer1 = -99999, answer2 = -99999, answer3 = -99999;
        if(col-1 > 0){
          answer1 = DorinsMethods.cost(row-1, col-1, row-1, col, row);
        }
        
        answer2 = DorinsMethods.cost(row-1, col, row-1, col, row);
        
        if(col + 1 < 11){
          answer3 = DorinsMethods.cost(row-1, col+1, row-1, col, row);
        }
        int fanswer = max(answer1,answer2,answer3);
        if(fanswer == answer1)
          return col-1;
        if(fanswer == answer2)
          return col;
        if(fanswer == answer3)
          return col+1;
      }
    }

  7. #7
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    hmm got it (i think)
    thanks peeps

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM