Last active
September 21, 2016 04:16
-
-
Save itsJarrett/0df5958875aecbcfc31260fc2240fd23 to your computer and use it in GitHub Desktop.
Karel Line Sorter :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void lineSorter() { | |
int lineAmount = 0; | |
turnRight(); | |
while (nextToABeeper()) { | |
lineAmount++; | |
move(); | |
} | |
int lineHeigths[] = new int[lineAmount]; | |
turnAround(); | |
for (int i = 0; i < lineAmount; i++) { | |
move(); | |
} | |
turnRight(); | |
for (int i = 0; i < lineAmount; i++) { | |
int lineHeight = 0; | |
while (nextToABeeper()) { | |
pickBeeper(); | |
move(); | |
lineHeight++; | |
} | |
turnAround(); | |
for (int j = 0; j < lineHeight; j++) { | |
move(); | |
} | |
turnAround(); | |
turnRight(); | |
move(); | |
turnLeft(); | |
lineHeigths[i] = lineHeight; | |
} | |
turnLeft(); | |
for (int i = 0; i < lineAmount; i++) { | |
move(); | |
} | |
turnRight(); | |
Arrays.sort(lineHeigths); | |
for (int i = 0; i < lineAmount; i++) { | |
for (int j = 0; j < lineHeigths[i]; j++) { | |
putBeeper(); | |
move(); | |
} | |
turnAround(); | |
for (int x = 0; x < lineHeigths[i]; x++) { | |
move(); | |
} | |
turnAround(); | |
turnRight(); | |
move(); | |
turnLeft(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment