Skip to content

Instantly share code, notes, and snippets.

@itsJarrett
Last active September 21, 2016 04:16
Show Gist options
  • Save itsJarrett/0df5958875aecbcfc31260fc2240fd23 to your computer and use it in GitHub Desktop.
Save itsJarrett/0df5958875aecbcfc31260fc2240fd23 to your computer and use it in GitHub Desktop.
Karel Line Sorter :)
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