1. Registered User
Join Date
Jan 2012
Location
Denmark
Posts
66

## Problem with logic

I going through the "C# / .NET / XNA" videos and I'm having some problem finding the "logic" in the codes.

Im in vol 2 atm and have done "Knowledge Review 4", but it took me very long time to figure how the code sould be set up.
Know I'm at "Knowledge Review 4" and I've done the first part but came up with close to 90 lines of code, while the guys from 3DBuzz used a lot less.
I'm know stuck in part 2 and have been trying for a very long time to figure it out but I really can't do it I know that I just can see the rest of the video but I really wanna do it my slef!

So I'm thinking if there are something I missed? Is there anything I can do to be able to see the code mere logic or just be able to put the code out more logic?

I'm really hope any of you guys out there can help me

//alpo

2. What is the question in that knowledge review?

Is it the one with absolute value?

3. Registered User
Join Date
Jan 2012
Location
Denmark
Posts
66
It's the one with loops. In the first part I made a program that could take a number from the user and make a line with numbers for exampel if the user write 5 the line will look like this "123454321". I was able to make that one but know I can only use 1 loop and only 1 statement inside of it.
But I don't just want to be able to do it but I wanna know if there is a way where I can learn to see the logic behind the code ?

4. Registered User
Join Date
Jan 2007
Posts
216
In math there are some problems like this:

Find the next number in the series:

1 4 7 10 __
10 8 6 4 2 _

these series are rather simple to solve , in the first one you simply add 3 to the number and in the second you subtract 2 starting at 10:

10-2=8
8-2=6
6-2=4
4-2=2
2-2=0

BUT we can also directly caluclate a number in the series, with out knowing all the previous numbers by subtracting s*position:

10-2 * 2 = 6
10-2 * 3 = 4
10-2 * 4 = 2
10-2 * 5 = 0

Now we want to apply the same thing to the series 1 2 3 4 5 4 3 2 1 . We now the full sequence, but we need to find out the rule with which it is created:

I don't want to spoil the answer, but try to fill this out and see if you can find a pattern:
5 - __ = 1
5 - __ = 2
5 - __ = 3
5 - __ = 4
5 - __ = 5
5 - __ = 4
5 - __ = 3
5 - __ = 2
5 - __ = 1

Also in math whenever you see something like this:
It screams absolute values.

I hope I haven't given to much away, or even worse confused you more. It is kind of a huge curveball they throw you, because the rule is really easy to program, but if you don't have the knowledge to see what you need to do there is no way to solve it.
Last edited by Dragonclaw1988; 02-15-2012 at 09:38 AM.

5. Registered User
Join Date
Jan 2012
Location
Denmark
Posts
66
I got it working know, the clue you gave me about absolute values helped I used about 1 hour to come up with the math and then about 5 mins writing it out in code
I can see that the way you put up this equation really helped, but I don't think I would have come up with it my self witch leads me back to my original questen.

Is there a way that I can learn to see the logic behind the code?
I was able to do the math when you put it up like that but I really didn't see it like that at all in the first place Is there any way I can like train to see it like that ?

6. It is kind of a huge curveball they throw you, because the rule is really easy to program, but if you don't have the knowledge to see what you need to do there is no way to solve it.
I also thought it was unfair for them to give this problem, since they never even talked about absolute value functions.
If you are familiar with math you will see it right away, but otherwise you probably won't get it.

I have seen posts from people that give up because they can not do the knowledge reviews, and this is really sad.
Just keep going on with the instruction and don't feel as though not being able to solve the knowledge reviews is a death blow

7. Registered User
Join Date
Jan 2012
Location
Denmark
Posts
66
So what you are saying is that I just have to keep on trying and then is will come at a point?

8. Registered User
Join Date
Jan 2007
Posts
216
yeah keep trying, that's pretty much the only advice I have. But also don't sweet yourself if you can't come up with the optimal solution. If they hadn't put on the restriction of only one loop and one direction inside, you would have been done in 2 min.

for loop from 1 to 5 , for loop from 4 to 1. and you're done...

9. Registered User
Join Date
Jan 2012
Location
Denmark
Posts
66
Thanks

I will just keep on going then

10. Registered User
Join Date
Jan 2010
Posts
61
some of the logic problems are fuzzy for me also... but, there is a point where things start to click..

Page 1 of 3 123 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•