Need Programming Assitance.

I actually don't know lol. I was just wondering if anyone can see why it keeps looping back into the algorithm function. It works properly when I enter any combination of clockwise moves and 180 turns, but not for 270 degree turns.
 
Code:
if ($algo eq 'L') {
&L();
} elsif ($algo eq 'R') {
&R();
} elsif ($algo eq 'U') {
&U();
} elsif ($algo eq 'D') {
&D();
} elsif ($algo eq 'F') {
&F();
} elsif ($algo eq 'B') {
&B();
}

I'm sure you can clean this up. You've even used it twice.

Another suggestion: Never use one variable for two different things.
 
Code:
if ($algo eq 'L') {
&L();
} elsif ($algo eq 'R') {
&R();
} elsif ($algo eq 'U') {
&U();
} elsif ($algo eq 'D') {
&D();
} elsif ($algo eq 'F') {
&F();
} elsif ($algo eq 'B') {
&B();
}

I'm sure you can clean this up. You've even used it twice.

Another suggestion: Never use one variable for two different things.

Yeah I'll turn that into a sub.

What did you mean by clean it up? I can't think of any way to do that.
 
Last edited:
Yes, the code is hideous. I haven't made anything in a while and it was 4am.
I just go straight for compile.
Well, I had no idea why it was looping when it shouldn't so I just bypassed the problem by expanding " ' " to two characters identical to the one preceding it. While I was doing that, I did it for the "2" as well and just duplicated the preceding character.
 
1. Use parameters
2. Use local variables
3. Don't reuse names (foreach $algo (@algo))

Just because a language lets you do something, doesn't mean you should. What are you trying to accomplish anyway? If you tell us, then maybe the programmers on the board can show you better examples.
 
1. Use parameters
2. Use local variables
3. Don't reuse names (foreach $algo (@algo))

Just because a language lets you do something, doesn't mean you should. What are you trying to accomplish anyway? If you tell us, then maybe the programmers on the board can show you better examples.

The reason for the (foreach $algo (@algo)) is because the scalar variable gets its values from the array.

I finding a way to calculate the degrees of any given set of moves. The number of times you would have to repeat that set in order to get the cube back to its initial position.
 
I'm familiar with what the foreach does, but I was saying it's more readable if the foreach individual variable is something different from the other one.

For example: foreach $move (@algo)

See? I know that I'm processing single moves of the larger algorithm.
 
This reminds me of the time I turned in some Java source code using only varying lengths of underscores as variables. My CompSci teacher just laughed. It compiled and ran with no problems so I got full marks still.
 
This reminds me of the time I turned in some Java source code using only varying lengths of underscores as variables. My CompSci teacher just laughed. It compiled and ran with no problems so I got full marks still.
That means that you have a teacher that understood you.
Compiling and running with no problem is the bare minimum a program should do and if nobody is ever going to look at the code after that is just fine

But there is ALWAYS someone going to look at the code later (most of the time it is going to be YOU) so writing code that can be understood later is ALWAYS important
 
Back
Top