Another hard C problem

This is a discussion on Another hard C problem within the C Programming forums, part of the General Programming Boards category; Another C programming problem I don't understand, any help please ? Question 2: Die Tipping NB: Die is the singular ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    London, UK
    Posts
    18

    Smile Another hard C problem

    Another C programming problem I don't understand, any help please ?




    Question 2: Die Tipping NB: Die is the singular of dice
    A normal die is a cube where the faces are numbered 1 through 6 and the numbers are arranged so that
    opposite faces add up to 7. In this question we will move a die on an 11 by 11 grid. Each square on this
    grid is the same size as the faces of the die; i.e. the die fits exactly onto each square on the grid.
    Imagine the die is placed on the grid so that the number 1 is uppermost and 6 is touching the grid. The
    die is now rotated so that 2 is towards the top of the grid and 5 is towards the bottom. This question uses
    a die that has 3 on the left and 4 on the right. We will call this the default orientation of the die.
    A move is made by tipping the die over one of the edges of the face that touches the grid. This will move
    the die one square on the grid and change the face that touches the grid. If the die is tipped off the left
    side of the grid it should be placed at the corresponding position (i.e. with the same y co-ordinate) on the
    right side of the grid, and vice versa. Similarly for the top and bottom of the grid (with the x co-ordinate
    staying the same).
    For example, suppose the die is in its default orientation in the middle of the grid. It now tips over the
    edge towards the bottom of the grid. The die moves one square closer to the bottom of the grid, and 5
    now touches the grid. 1 is now towards the bottom of the grid, 6 the top, 2 will be uppermost and 3 and
    4 will remain on the left and right respectively.
    The die also has a heading, which is the direction on the grid it last moved.
    The rules for moving the die are as follows:
    1. Each square on the grid contains a number (1, 2, 3, 4, 5 or 6). Add the number on the current square
    to the value that is uppermost on the die. If this sum is greater than 6, subtract 6 from the sum.
    2. Replace the number on the grid with this new value.
    3. Depending on this value perform one of the following actions:
    • 1 or 6 move
    one square according to the heading;
    • 2 move
    one square in the direction 90 clockwise to the heading;
    • 3 or 4 move
    one square in the opposite direction to the heading;
    • 5 move
    one square in the direction 90 anti-clockwise to the heading.

    Write a program that models the die moving on the grid.
    Your program should first read in a 3!3 grid, which will be in the form of three lines
    of three integers (between 1 and 6 inclusive). This 3!3 grid should be used as the
    centre section of the 11!11 grid for the simulation. The remaining squares of the grid
    will start with the value 1.
    In each case the die begins in the centre of the 11!11 grid, in the default orientation,
    with a heading towards the top of the grid.
    Until your program terminates you should repeatedly input an integer, and then:
    • If you receive a positive integer n (1 " n " 100) you should make n moves.
    • If you receive the number 0 your program should terminate immediately.
    • Ignore any other input.
    After each positive integer you should output the 3!3 grid surrounding the die. For
    each square on this grid that is outside the 11!11 grid you should output an X.



    Sample Run example :
    1 3 5
    1 6 5
    1 1 5
    1

    111
    135
    115

    1

    111
    251
    151


    3

    221
    161
    131


    0
    Last edited by alexbcg; 11-22-2010 at 02:20 PM.

  2. #2

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    London, UK
    Posts
    18
    I am not asking anyone to do it for me, merely for help on a complex (for me) problem I am having trouble doing and was wondering whether anyone/more experienced and proficient programmers could point me in the right direction/suggest stuff and methods because I am not that good and would therefore appreciate some help. I don't just want the answers, but would like some discussion or help on it which is what I understand this forum is for.

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    The point is that you have to initiate this process usually by saying: "I am thinking of doing this, but I can't figure out x or y". If we do the brainstorming for you, not only is it a waste of our time because we can probably solve the problem anyway, but it will remove the benefit of learning from you.

    So, give it some thought, come back here and post how you are going to go about it and we will work from there.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    London, UK
    Posts
    18
    Quote Originally Posted by claudiu View Post
    The point is that you have to initiate this process usually by saying: "I am thinking of doing this, but I can't figure out x or y". If we do the brainstorming for you, not only is it a waste of our time because we can probably solve the problem anyway, but it will remove the benefit of learning from you.

    So, give it some thought, come back here and post how you are going to go about it and we will work from there.
    I realise you are indeed completely correct and I had misunderstood how forums work (my first post) but I shall work out a strategy of sorts and shall be back with a few more relevant and hopefully productive questions/methods in order to seek precise and productive help from experts such as yourself

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by alexbcg View Post
    I realise you are indeed completely correct and I had misunderstood how forums work (my first post) but I shall work out a strategy of sorts and shall be back with a few more relevant and hopefully productive questions/methods in order to seek precise and productive help from experts such as yourself
    Code samples are usually a pretty good idea, in these parts....

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    London, UK
    Posts
    18
    However I am having difficulty getting my head around the program representation of a physical 3d real world concept, and all the tests I have attempted (believe you me theres an hours worth of that) screw up and are generally nonsensical. I have basically no idea how to go about this and everything I try = failure = not being able to get a foothold in the problem I am unable/too bad/stupid to grasp such a concept... but I'll keep trying and come back with a better idea, sorry if I wasted your time.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by alexbcg View Post
    However I am having difficulty getting my head around the program representation of a physical 3d real world concept, and all the tests I have attempted (believe you me theres an hours worth of that) screw up and are generally nonsensical. I have basically no idea how to go about this and everything I try = failure = not being able to get a foothold in the problem I am unable/too bad/stupid to grasp such a concept... but I'll keep trying and come back with a better idea, sorry if I wasted your time.
    Ok stop trying to write code... concentrate on understanding the problem. You can't code anything you don't understand. Get a die and tip it... see the problem in real life...

  9. #9
    Registered User
    Join Date
    Nov 2010
    Location
    London, UK
    Posts
    18
    Quote Originally Posted by CommonTater View Post
    Ok stop trying to write code... concentrate on understanding the problem. You can't code anything you don't understand. Get a die and tip it... see the problem in real life...
    Ok, so basically, I can visualize what the die looks like and the rules associated to it's movement, however, I don't really understand this whole heading business, and how can I use the 3!3 grid to link into t he 11!11 grid (not thinking about programming at this stage), and how the input values affect the behaviour of my die?

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Yeah I read it both here and on the contest PDF... it's as clear as mud.

    About all I can offer, beyond what I have is to try to reduce the problem to it's simplest steps...

  11. #11
    Registered User
    Join Date
    Nov 2010
    Location
    London, UK
    Posts
    18
    yes, because I am preparing for the 2011 one in 2 weeks and really need to up my game, have been doing past papers but it's really hard! I am still working on that question :P

  12. #12
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Seems pretty clear to me. I could take a stab at this, and we could compare our approaches. If anyone is interested, that is.

  13. #13
    Registered User
    Join Date
    Nov 2008
    Posts
    119
    Quote Originally Posted by alexbcg View Post
    Ok, so basically, I can visualize what the die looks like and the rules associated to it's movement, however, I don't really understand this whole heading business, and how can I use the 3!3 grid to link into t he 11!11 grid (not thinking about programming at this stage), and how the input values affect the behaviour of my die?
    Do you not understand what the word heading means? It's the direction you are current moving in.

    For the 3x3 and 11x11 grid. Draw an 11x11 grid on a sheet of paper. Draw a 3x3 grid on a sheet of paper using squares of the same size. Cut out the 3x3 grid. Fill the 3x3 grid with numbers. Place it on the center of the 11x11 grid. Fill empty squares with 1s.

    That's what they want you to program for that part.

    Anyway, if you are having trouble, don't try to solve the whole problem at once. First, write some code that represents a die. Then some code that can turn it. Then some code that can put it on a grid. etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  2. small reference problem
    By DavidP in forum C++ Programming
    Replies: 6
    Last Post: 06-21-2004, 07:29 PM
  3. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 12:30 PM
  4. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 07:34 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21