Scores
This section will be filled in as submissions are entered.
Normal
1. bopjesvla Perl 54
2. edc65 Javascript (ES6) 91
3. name language score
4. name language score
5. name language score
Bonus Round
1. name language score
2. name language score
3. name language score
4. name language score
5. name language score
Karel J. AlphaBot
Background
A popular introductory course to Java is Karel J. Robot (I'm using it myself). The robot interacts with a grid of streets (positive integer y-coordinates) and avenues (positive integer x-coordinates) as well as beepers, which can be placed and stored on the grid (note that Karel and any beepers can only exist on lattice points). Karel (the robot) is only to perform five actions: move forward by 1, turn left in place, put down a beeper, pick up a beeper, and turn itself off.
In my Computer Science class, one of our first assignments was to program Karel to learn how to turn right, turn around, and perform the combined action of moving forward by 1 and putting down a beeper. An assignment a few days later was to use these methods and write new methods to produce letters of the alphabet.
Naturally, once I finished this assignment, I wrote more methods to make every letter of the alphabet, as well as the ten numerical digits, and I plan to figure out how to make a sort of word processor out of the robot, where a string would be entered to STDIN and the robot would put beepers on the grid in a way that resembled the letters.
Every time I wrote private void draw#
for each character #
, I added a comment after it that would tell me abbreviations for the sequence of commands I'd need.
I have the following commands (written in pseudocode) at my disposal (clarification - these are the only useful commands).
Turn Left
Rotate the robot 90˚ counterclockwise
Abbreviated as "l"
Turn Right
Rotate the robot 90˚ clockwise
Abbreviated as "r"
Move
Move one space forwards
Abbreviated as "m"
Put Beeper
Put a beeper on the spot that Karel is on
Abbreviated as "p"
Drop Beeper
Move, then Put Beeper
Abbreviated as "d"
Turn Around
Turn Left, then Turn Left
Abbreviated as "a"
Conditions
The robot must proceed in the following order.
- The robot starts on the bottom left corner of the 5xN rectangle of minimal area the letter will be drawn in.
- The robot draws the letter.
- The robot moves to the bottom right corner of the rectangle.
- The robot moves two spaces to the right and must face north/up
Let's work through an example. Suppose we want to draw A
. The location of the robot is the letter that indicates its direction (north, south, east, west). The letter is capitalized if the robot is on a spot with a beeper and lowercase if the robot is on a spot without a beeper. o
represents spots with beepers and .
represents spots without beepers.
As we will see later, A
is this.
.ooo.
o...o
ooooo
o...o
o...o
Here is one possible solution.
Grids ..... ..... ..... ..... ..... ..... ..... ..... .....
..... ..... ..... ..... ..... ..... ..... ..... .....
..... ..... ..... N.... E.... oE... ooE.. oooE. oooW.
..... ..... N.... o.... o.... o.... o.... o.... o....
n.... N.... o.... o.... o.... o.... o.... o.... o....
Letters p d d r d d d a
..... ..... ..... ..... ..... n.... e.... .E... .oE..
..... ..... ..... ..... N.... o.... o.... o.... o....
ooWo. oWoo. Wooo. Nooo. oooo. oooo. oooo. oooo. oooo.
o.... o.... o.... o.... o.... o.... o.... o.... o....
o.... o.... o.... o.... o.... o.... o.... o.... o....
m m m r d m r d d
.ooE. .oooe .ooos .ooo. .ooo. .ooo. .ooo. .ooo.
o.... o.... o.... o...S o...o o...o o...o o...o
oooo. oooo. oooo. oooo. ooooS ooooo ooooo ooooo
o.... o.... o.... o.... o.... o...S o...o o...o
o.... o.... o.... o.... o.... o.... o...S o...E
d m r d d d d l
The final mml
to complete the fourth bullet is implicit because it appears in every letter and because I don't want to go back and add another two columns to everything in the above proposed solution.
Thus, one solution to make A
is pddrdddammmrdmrdddmrddddlmml
.
Note that this doesn't have to be your solution. Your algorithm can go through every column, putting beepers in the proper places and not relying on where other beepers have been placed or will be placed. No matter what your algorithm is, the robot can only place one beeper per space on the grid.
The program
Your program will take as its input a 5xN grid of what the grid for the letter is. Note that there is no robot on the input; the robot is assumed to be on the bottom left (southwest) corner, facing north.
The output will be the sequence of letters that are the shorthand for the sequence.
Sample inputs
.ooo.
o...o
ooooo
o...o
o...o
o...o.ooooo
o...o...o..
ooooo...o..
o...o...o..
o...o.ooooo
Sample outputs
pddrdddammmrdmrdddmrddddlmml
prmmmlmlmmdrdrdddlmlmmdrdrmmmdrddddlmmlprdddlmldmmrmrmdmlmldmmrdrddddrmmmdlmml
This is code golf, fellas. Standard CG rules apply. Shortest code in bytes wins.
Bonus Round
Rules
If you want to participate in the bonus round, be sure to make your codes move-efficient! Below is a library of all of the 5x5 letters my program creates when it runs. The objective of the bonus round is to write a program that prints a sequence for ABCDEFGHIJKLMNOPQRSTUVWXYZ
that contains as few moves as possible. There is no input to STDIN. Code will be graded not on the length of the code but on its "move score." The move score is designed to discourage sweeper algorithms that visit every point in the rectangle.
d: 1
l: 1
m: 4
p: 1
r: 1
Letters
.ooo. oooo. ooooo oooo. ooooo ooooo .oooo o...o
o...o o...o o.... o...o o.... o.... o.... o...o
ooooo oooo. o.... o...o oooo oooo. o.ooo ooooo
o...o o...o o.... o...o o.... o.... o...o o...o
o...o oooo. ooooo oooo. ooooo o.... oooo. o...o
ooooo ....o o...o o.... ooooo o...o ooooo oooo.
..o.. ....o o..o. o.... o.o.o oo..o o...o o...o
..o.. ....o oo... o.... o.o.o o.o.o o...o oooo.
..o.. o...o o..o. o.... o...o o..oo o...o o....
ooooo .ooo. o...o ooooo o...o o...o ooooo o....
oooo. oooo. ooooo ooooo o...o o...o o...o o...o
o..o. o...o o.... ..o.. o...o o...o o...o .o.o.
o..o. oooo. ooooo ..o.. o...o .o.o. o.o.o ..o..
oooo. o..o. ....o ..o.. o...o .o.o. o.o.o .o.o.
....o o...o ooooo ..o.. ooooo ..o.. ooooo o...o
o...o ooooo
.o.o. ...o.
..o.. ..o..
.o... .o...
o.... ooooo
The same procedure as the original challenge must be followed: letters must be drawn one at a time with a space separation between each letter.
Standard CG rules apply. Entry with the lowest move score wins.
To summarize, both codes will essentially do the same things. The first code should have a minimal number of bytes in the code, and the second code should use the smallest number of moves.