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
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.
Originally Posted by rags_to_riches
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
Originally Posted by claudiu
Code samples are usually a pretty good idea, in these parts....
Originally Posted by alexbcg
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...
Originally Posted by alexbcg
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?
Originally Posted by CommonTater
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...
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
Seems pretty clear to me. I could take a stab at this, and we could compare our approaches. If anyone is interested, that is. :)
Do you not understand what the word heading means? It's the direction you are current moving in.
Originally Posted by alexbcg
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.