Skip to content

Instantly share code, notes, and snippets.

@ishmaelmakitla
Created February 11, 2016 08:10
Show Gist options
  • Save ishmaelmakitla/43dd6b37f6b770bb7e35 to your computer and use it in GitHub Desktop.
Save ishmaelmakitla/43dd6b37f6b770bb7e35 to your computer and use it in GitHub Desktop.
This is the code for painting the Right Angle Hash Code 2016 Practice Problem using 107 commands. You are welcome to make improvements and reduce the number of commands used.
package za.co.pta.gdg.hashcode.practice;
/**
* This code paints the Right Angle Hash Code Practice problem using 107 commands.
* It makes use of the HashCodeCommandProcessor - see this gist: https://gist.github.com/ishmaelmakitla/920632ae6c35805d9aa3
*
* */
public class RightAngleHashCodePracticeApp {
/**
* Right Angle Practice
*/
char[][] triaglePictureMatrix = HashCodeCommandProcessor.createPictureMatrix(40, 200);
//excuse the name triangle - I wrote this very late in the evening...
HashCodeCommandProcessor triangleCommandsProcessor = new HashCodeCommandProcessor(triaglePictureMatrix);
/*
* The 'hammer' part forming Blank-C shape
*/
//11x11 square in front of the blank-C
triangleCommandsProcessor.processPaintSquareCommand(18, 69, 5);
//another 11x11 square next to the above
triangleCommandsProcessor.processPaintSquareCommand(18, 80, 5);
//two vertical lines to complete the block infront of blank-C
triangleCommandsProcessor.processPaintLineCommand(13,86,23,86);
triangleCommandsProcessor.processPaintLineCommand(13,87,23,87);
//horizontal line at the botton of the 11x11 square
triangleCommandsProcessor.processPaintLineCommand(24,63,24,87);
//3 3x3 sqaures to form the handle of the "hammer"
triangleCommandsProcessor.processPaintSquareCommand(18, 53, 1);
triangleCommandsProcessor.processPaintSquareCommand(18, 56, 1);
triangleCommandsProcessor.processPaintSquareCommand(18, 59, 1);
triangleCommandsProcessor.processPaintSquareCommand(18, 62, 1);
//horizontal line at the botton of the 3x3 square to complete the hammer handle
triangleCommandsProcessor.processPaintLineCommand(20,52,20,63);
//the 2 hashes making the curve of the handle
triangleCommandsProcessor.processPaintLineCommand(18,51,19,51);
//the small "bubble" on the right-hand corner of the hammer
triangleCommandsProcessor.processPaintLineCommand(11,92,11,94);
triangleCommandsProcessor.processPaintLineCommand(12,91,12,95);
triangleCommandsProcessor.processPaintLineCommand(13,93,13,94);
//the two lines above the hammer
triangleCommandsProcessor.processPaintLineCommand(7,76,7,82);
triangleCommandsProcessor.processPaintLineCommand(8,75,8,83);
//the small hat of the painted C
//3x3 square
triangleCommandsProcessor.processPaintSquareCommand(6, 14, 1);
//padding vertical line
triangleCommandsProcessor.processPaintLineCommand(5,16,7,16);
//padding horizontal line
triangleCommandsProcessor.processPaintLineCommand(8,13,8,16);
//the leading 4x3 block before the painted C
//3x3 square
triangleCommandsProcessor.processPaintSquareCommand(10, 6, 1);
//padding vertical line
triangleCommandsProcessor.processPaintLineCommand(9,8,11,8);
//the leading 3x2 block
triangleCommandsProcessor.processPaintLineCommand(13,5,13,8);
triangleCommandsProcessor.processPaintLineCommand(14,5,14,8);
//lines joining the leading block to the painted-C
triangleCommandsProcessor.processPaintLineCommand(11,9,11,16);
triangleCommandsProcessor.processPaintLineCommand(12,9,12,16);
//and the 2 hashes below the lines above
triangleCommandsProcessor.processPaintLineCommand(13,11,13,12); //convert to a horizontal line
//now drawing the painted-C
/*
* Bottom Part of Painted-C
*/
//7x7 squares for the bottom-part of the C
//the 2 lines (6x2) forming part of the bottom of the painted C and also joins the leading part behind painted-C and the hammer-head in front
triangleCommandsProcessor.processPaintLineCommand(25,4,25,63);
triangleCommandsProcessor.processPaintLineCommand(26,4,26,63);
//5 horizontal lines padding the bottom part of painted-C
triangleCommandsProcessor.processPaintLineCommand(27,20,27,63);
triangleCommandsProcessor.processPaintLineCommand(28,21,28,63);
triangleCommandsProcessor.processPaintLineCommand(29,21,29,63);
triangleCommandsProcessor.processPaintLineCommand(30,21,30,63);
triangleCommandsProcessor.processPaintLineCommand(31,21,31,63);
/*
* The middle part of the painted-C
*/
//3x3 squares hooking back of C
triangleCommandsProcessor.processPaintSquareCommand(10, 17, 1);
//erase a cell on the second row of the first 3x3 square
triangleCommandsProcessor.processEraseCellCommand(10,16);
triangleCommandsProcessor.processPaintSquareCommand(10, 20, 1);
//13x13 square centred at [18,26]
//triangleCommandsProcessor.processPaintSquareCommand(18, 27, 6);
triangleCommandsProcessor.processPaintSquareCommand(16, 25, 4); //change to 9x9
//9x9 square padding the middle part of the C
triangleCommandsProcessor.processPaintSquareCommand(16, 34, 4);
//to complete the middle-part of C, padding 5x5 square
triangleCommandsProcessor.processPaintSquareCommand(16, 41, 2);
//now the 5x5 square behind the painted-C - replace with horizontal lines
triangleCommandsProcessor.processPaintLineCommand(22,11,22,43);
triangleCommandsProcessor.processPaintLineCommand(23,10,23,43);
triangleCommandsProcessor.processPaintLineCommand(24,10,24,43);
triangleCommandsProcessor.processPaintLineCommand(19,39,19,43);
triangleCommandsProcessor.processPaintLineCommand(20,39,20,43);
triangleCommandsProcessor.processPaintLineCommand(21,21,21,43);
/*
* The top-part of painted C
*/
//5 horizontal lines forming top of painted-C
triangleCommandsProcessor.processPaintLineCommand(12,39, 12, 58);
triangleCommandsProcessor.processPaintLineCommand(13,39, 13, 57);
triangleCommandsProcessor.processPaintLineCommand(9,21, 9, 57);
triangleCommandsProcessor.processPaintLineCommand(10,21, 10, 58);
triangleCommandsProcessor.processPaintLineCommand(11, 21, 11, 58);
//The sum of all the commands above paint the left-hand part of the picture
//Next up we send commands to paint the middle part of the picture
//The sum of all the commands above paint the middle-hand part of the picture
//Next up we send commands to paint the LAST (right-hand) part of the picture
//3x3 square to form the tip in the bottom-middle
triangleCommandsProcessor.processPaintSquareCommand(30, 114, 1);
//pass a verticl line
triangleCommandsProcessor.processPaintLineCommand(29, 116, 32, 116);
//finally a horizontal line
triangleCommandsProcessor.processPaintLineCommand(32, 113, 32, 115);
//horizontal lines forming a small cap on top of the block above
triangleCommandsProcessor.processPaintLineCommand(25, 109, 25, 112);
triangleCommandsProcessor.processPaintLineCommand(26, 109, 26, 112);
triangleCommandsProcessor.processPaintLineCommand(27, 105, 27, 112);
triangleCommandsProcessor.processPaintLineCommand(28, 105, 28, 112);
//11x11 block
triangleCommandsProcessor.processPaintSquareCommand(19, 101, 5);
//padding with 2 horizontal lines to complete the block
triangleCommandsProcessor.processPaintLineCommand(14, 107, 14, 116);
triangleCommandsProcessor.processPaintLineCommand(15, 107, 15, 116);
//padding with 9x9 block
triangleCommandsProcessor.processPaintSquareCommand(20, 111, 4);
//padding with a vertical line
triangleCommandsProcessor.processPaintLineCommand(16, 116, 23, 116);
//bottom block of the middle part
triangleCommandsProcessor.processPaintLineCommand(25, 123, 25, 149);
triangleCommandsProcessor.processPaintLineCommand(26, 123, 26, 149);
triangleCommandsProcessor.processPaintLineCommand(27, 123, 27, 149);
triangleCommandsProcessor.processPaintLineCommand(28, 123, 28, 149);
triangleCommandsProcessor.processPaintLineCommand(29, 123, 29, 149);
//
triangleCommandsProcessor.processPaintLineCommand(22, 140, 22, 149);
triangleCommandsProcessor.processPaintLineCommand(23, 140, 23, 149);
triangleCommandsProcessor.processPaintLineCommand(24, 140, 24, 149);
//
triangleCommandsProcessor.processPaintLineCommand(9, 117, 9, 149);
triangleCommandsProcessor.processPaintLineCommand(10, 117, 10, 149);
triangleCommandsProcessor.processPaintLineCommand(11, 117, 11, 149);
triangleCommandsProcessor.processPaintLineCommand(12, 117, 12, 149);
triangleCommandsProcessor.processPaintLineCommand(13, 117, 13, 149);
triangleCommandsProcessor.processPaintLineCommand(14, 117, 14, 149);
triangleCommandsProcessor.processPaintLineCommand(15, 117, 15, 149);
triangleCommandsProcessor.processPaintLineCommand(16, 117, 16, 149);
triangleCommandsProcessor.processPaintLineCommand(17, 117, 17, 149);
triangleCommandsProcessor.processPaintLineCommand(18, 117, 18, 149);
triangleCommandsProcessor.processPaintLineCommand(19, 117, 19, 149);
triangleCommandsProcessor.processPaintLineCommand(20, 117, 20, 149);
triangleCommandsProcessor.processPaintLineCommand(21, 117, 21, 149);
/*
* The tower
*/
//11x11 Square
triangleCommandsProcessor.processPaintSquareCommand(10, 161, 5);
//add 9x9 square (s=4)
triangleCommandsProcessor.processPaintSquareCommand(20, 160, 4);
//now print two vertical lines to the right of this 9x9 square
triangleCommandsProcessor.processPaintLineCommand(16, 165, 24, 165);
triangleCommandsProcessor.processPaintLineCommand(16, 166, 24, 166);
/*
* Last part of the picture - far right
*/
//vertical line forming the small tower at the bottom
triangleCommandsProcessor.processPaintLineCommand(29, 169, 36, 169);
triangleCommandsProcessor.processPaintLineCommand(29, 170, 36, 170);
triangleCommandsProcessor.processPaintLineCommand(29, 171, 36, 171);
triangleCommandsProcessor.processPaintLineCommand(29, 172, 36, 172);
//the two trailing hashes on the right of this tower
triangleCommandsProcessor.processPaintLineCommand(33, 173, 34, 173);
//
triangleCommandsProcessor.processPaintLineCommand(25, 173, 25, 191);
triangleCommandsProcessor.processPaintLineCommand(26, 173, 26, 191);
triangleCommandsProcessor.processPaintLineCommand(27, 173, 27, 191);
triangleCommandsProcessor.processPaintLineCommand(28, 173, 28, 191);
triangleCommandsProcessor.processPaintLineCommand(29, 173, 29, 190);
//
triangleCommandsProcessor.processPaintLineCommand(13, 174, 13, 190);
triangleCommandsProcessor.processPaintLineCommand(14, 173, 14, 190);
triangleCommandsProcessor.processPaintLineCommand(15, 173, 15, 190);
triangleCommandsProcessor.processPaintLineCommand(16, 173, 16, 190);
triangleCommandsProcessor.processPaintLineCommand(17, 173, 17, 190);
triangleCommandsProcessor.processPaintLineCommand(18, 173, 18, 190);
//
triangleCommandsProcessor.processPaintLineCommand(5, 187, 5, 194);
triangleCommandsProcessor.processPaintLineCommand(6, 187, 6, 194);
triangleCommandsProcessor.processPaintLineCommand(7, 183, 7, 194);
triangleCommandsProcessor.processPaintLineCommand(8, 183, 8, 186);
triangleCommandsProcessor.createCommandsFile();
System.out.print(triangleCommandsProcessor.showAsString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment