15,312,353 members
1.00/5 (1 vote)
See more:
Hello Codeproject,

Assuming I have a row that follows like so:

0 1 2
3 4 5
6 7 8

And the number starts at 4, but I can only add or remove one, so saying;

-1 and -1 would equal to 0.
-1 and 0 would equal to 3.

Any ideas?
Posted
Comments
[no name] 8-Jul-13 15:59pm

Smells of homework. What have you tried?
Deviant Sapphire 8-Jul-13 16:00pm

Not really homework, this is for a project of mine but I do not have an idea. I thought about multiplying the number by three, but that didn't work out well.

Solution 2

I think I know what you're trying to say here, so here's an attempt at solving this (if I'm way off let me know, your description is a little vague):

Well you could use a 2-dimensional array, representing your grid, then use your -1/0/+1 as a change in the indexes, but that's more than you really need.

Look at it this way, what changes do those numbers really result in? The first moves you left or right, no matter where you are, the results in adding the same to the number (e.g. you start at 4, the first number is +1, you move to 5, which is 4 + 1). So just add the first number to 4. The second number moves you up or down. These all result in a change of 3*[second number] (e.g. you;re at 3, the second number is -1, you add -1*3 to 3 and get: 3 + (-1 * 3) = 0).

So the simplest way is:

4 + [first number] + [second number] * 3
Comments
Deviant Sapphire 8-Jul-13 16:21pm

Thank you I really appreciate the help and this did solve it!
Tim Carmichael 8-Jul-13 16:44pm

Looking at the set of numbers and the offered solution, please keep in mind what the desired behaviour is if the starting point is already on a edge (ie: not 4).
If you start with 0, what do you want to happen if the first number is -1? Do you wrap to 2 or ignore the value?
Deviant Sapphire 9-Jul-13 21:04pm

No this is exactly what I meant, I just followed your logic and it's easier for me to figure out next problems. Thanks a lot! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 CPallini 315 OriginalGriff 150 Patrice T 90 Richard Deeming 85 Richard MacCutchan 70
 OriginalGriff 4,329 Richard MacCutchan 1,673 CPallini 1,415 Richard Deeming 948 Patrice T 805

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}