diff --git a/day18/input b/day18/input new file mode 100644 index 0000000..da8bc3e --- /dev/null +++ b/day18/input @@ -0,0 +1,678 @@ +R 10 (#090220) +U 4 (#61ce73) +R 2 (#27ac30) +D 4 (#6e7db3) +R 9 (#42fb60) +U 2 (#267e43) +R 3 (#4a73a0) +U 3 (#0da863) +L 7 (#464882) +U 3 (#667693) +L 4 (#6ed2b2) +U 8 (#1efed3) +L 6 (#898ac2) +D 8 (#596eb3) +L 3 (#4a1fe2) +U 4 (#1c92f3) +L 4 (#42f8d0) +U 3 (#5d3b13) +L 6 (#2913d0) +U 8 (#1941a3) +L 6 (#401a90) +D 9 (#1941a1) +L 3 (#4f3ef0) +D 2 (#53b9d3) +L 3 (#0e2a00) +D 4 (#201683) +L 7 (#547ba0) +D 4 (#662e23) +L 9 (#814d30) +D 2 (#662e21) +L 6 (#0d69f0) +D 8 (#201681) +R 4 (#9da8d0) +D 10 (#3bef23) +L 4 (#235c92) +D 12 (#385aa3) +L 4 (#859100) +D 2 (#7489f3) +L 3 (#479820) +D 9 (#23dbc3) +L 5 (#3f40a2) +U 9 (#345f23) +L 5 (#054280) +U 5 (#7cd843) +R 5 (#054282) +U 7 (#00d753) +R 4 (#495402) +U 5 (#01d321) +L 4 (#131fa0) +U 9 (#67f181) +L 5 (#131fa2) +U 3 (#484a11) +R 11 (#449482) +U 4 (#40f083) +R 3 (#79b112) +U 4 (#03fa03) +L 5 (#9d0da0) +U 6 (#42a593) +L 5 (#a14cf2) +D 6 (#0e7581) +L 4 (#1b7142) +U 5 (#943c61) +L 5 (#251122) +U 4 (#203bd1) +L 5 (#782ad2) +U 6 (#579893) +R 5 (#a1c232) +U 3 (#5cdfa3) +L 3 (#07ec72) +U 10 (#0e7583) +L 6 (#86c2f2) +U 8 (#2d6c93) +R 6 (#2f99f0) +D 4 (#5c8973) +R 4 (#4b9c00) +D 8 (#844383) +R 5 (#5874b0) +D 4 (#083593) +R 3 (#0656e0) +D 7 (#00a893) +R 4 (#512100) +U 6 (#0bc123) +R 5 (#5d94f0) +U 5 (#54fef3) +R 3 (#3cf440) +U 6 (#34bb23) +R 2 (#2e88f0) +U 10 (#1f8b71) +R 4 (#2a6b20) +U 5 (#956d41) +R 9 (#47de90) +D 5 (#0d51e1) +R 6 (#660ce0) +D 6 (#09bfe1) +L 7 (#471c70) +D 4 (#1bf301) +L 4 (#35d600) +D 6 (#47d3b1) +R 9 (#0a6000) +D 3 (#acfc31) +R 2 (#0b2850) +D 8 (#0a4571) +R 4 (#88cfe0) +U 13 (#46fa21) +R 2 (#50e990) +U 10 (#3beb21) +R 3 (#77a972) +U 5 (#853671) +R 6 (#779852) +D 4 (#110871) +R 10 (#5bb5c0) +U 4 (#570241) +R 9 (#266ab0) +U 5 (#2b46c1) +L 10 (#7d5450) +U 6 (#53d241) +L 8 (#26cbf2) +U 5 (#7fbd91) +L 7 (#01d962) +U 9 (#0a2a51) +R 6 (#a49cd2) +U 4 (#39f461) +R 6 (#47dd50) +U 3 (#57b491) +R 4 (#597fa0) +U 5 (#57b493) +R 3 (#2be530) +U 3 (#304e21) +R 6 (#398860) +U 6 (#5d17e3) +R 4 (#64bdb0) +U 5 (#8d7a13) +R 6 (#26dea0) +U 8 (#5d6ab3) +R 9 (#5d7c80) +U 6 (#1e3dd3) +R 11 (#5f4260) +U 5 (#4781f1) +R 2 (#9acef2) +U 3 (#2bebd1) +R 4 (#0f9132) +U 8 (#3f3b41) +R 3 (#aa6020) +U 3 (#32e981) +R 3 (#1f6210) +U 10 (#11dbb1) +R 7 (#0fdc60) +D 7 (#225c03) +R 6 (#2a9790) +D 6 (#30fb13) +R 3 (#1d9890) +U 5 (#4f4fb3) +R 6 (#1d9892) +U 6 (#54c773) +R 7 (#5c5340) +U 3 (#42ccd3) +R 4 (#6c5f50) +D 4 (#54deb3) +R 5 (#346460) +U 4 (#587ed3) +R 5 (#52d9e0) +U 4 (#2ca473) +R 3 (#60a9c2) +U 6 (#46a783) +R 6 (#60a9c0) +U 4 (#44b7c3) +R 6 (#4ee4d0) +U 6 (#5ff893) +R 2 (#822bf2) +U 4 (#135f03) +R 8 (#895082) +D 8 (#5dd3f3) +R 3 (#3705f2) +U 5 (#330ca3) +R 3 (#479970) +D 5 (#6713d3) +R 2 (#6efa40) +D 8 (#1a84c3) +R 3 (#2dc650) +U 10 (#364363) +R 3 (#7b5f50) +U 3 (#703961) +R 3 (#23de92) +D 5 (#0753d3) +R 8 (#7664c2) +D 5 (#0753d1) +L 2 (#638da2) +D 7 (#3c7b51) +L 9 (#8455d0) +D 2 (#2c3021) +L 3 (#797b20) +D 5 (#444701) +L 4 (#495820) +D 6 (#173ab1) +L 7 (#30db32) +D 4 (#80ebf1) +R 6 (#30db30) +D 9 (#69de41) +R 4 (#77ebd0) +D 5 (#0561e1) +R 4 (#46de40) +D 4 (#9b6fe1) +R 11 (#4d17b0) +D 3 (#2329e1) +R 2 (#6c6980) +D 3 (#818f43) +R 7 (#8247f0) +D 10 (#68ebd3) +R 4 (#0cbf10) +D 4 (#9ec973) +L 11 (#44dfe0) +D 4 (#4d5981) +L 3 (#24a940) +D 4 (#29dba1) +L 5 (#473312) +D 9 (#868e71) +L 7 (#473310) +D 4 (#09f1b1) +L 4 (#628210) +U 5 (#818f41) +L 11 (#0a8230) +U 5 (#6ac553) +L 3 (#167900) +U 3 (#53d473) +L 3 (#2bd770) +D 4 (#408de3) +L 6 (#917dc0) +D 5 (#408de1) +R 6 (#103f40) +D 7 (#4d5b33) +R 3 (#388600) +D 3 (#9782a3) +R 8 (#60fec0) +D 3 (#7b0341) +R 8 (#1eb200) +D 4 (#312db1) +R 3 (#58fa10) +U 5 (#1a60c3) +R 4 (#3cb940) +U 2 (#1a60c1) +R 7 (#3d4bd0) +D 5 (#312db3) +L 7 (#21a720) +D 5 (#69da91) +L 11 (#08f6f0) +D 4 (#2b1111) +L 6 (#99d042) +D 3 (#4a68e1) +L 5 (#0e1c52) +D 5 (#3487f1) +L 7 (#a7ec90) +D 7 (#2bdcd1) +L 3 (#214032) +D 7 (#28ec31) +R 5 (#55c3e0) +D 2 (#79c001) +R 10 (#55c3e2) +D 6 (#700531) +R 5 (#6a9e12) +D 10 (#688521) +R 3 (#366c22) +D 3 (#6e5463) +R 5 (#30a512) +D 5 (#129f73) +L 6 (#8db872) +D 2 (#54c511) +L 4 (#4de992) +D 4 (#2c2ec1) +R 4 (#589972) +D 6 (#688523) +R 6 (#5f6de2) +D 4 (#01ea61) +R 5 (#47a442) +U 8 (#85ce21) +R 5 (#47a440) +U 7 (#3b18e1) +L 5 (#40c622) +U 4 (#14af21) +R 7 (#5edf22) +U 5 (#671003) +R 2 (#1b29e2) +U 4 (#273d33) +R 10 (#1b29e0) +U 6 (#493353) +R 3 (#049182) +D 7 (#7fe163) +R 5 (#3a4a52) +D 7 (#005723) +R 4 (#383002) +U 3 (#04e0f3) +R 4 (#782dc2) +U 6 (#8d97f3) +L 4 (#2569e2) +U 5 (#415d41) +R 5 (#27b292) +D 2 (#1c9fa1) +R 2 (#21e3e2) +D 7 (#9ead41) +R 5 (#21e3e0) +D 3 (#15cf41) +R 5 (#382a10) +D 4 (#2db171) +R 7 (#607330) +D 5 (#210cb1) +R 3 (#722700) +D 3 (#58a1d1) +R 4 (#559e92) +D 6 (#23d4e1) +R 3 (#7cfba2) +D 6 (#570981) +R 5 (#382a12) +D 3 (#10dff1) +R 4 (#2dd3b2) +D 5 (#29f051) +R 8 (#5c5322) +U 5 (#29f053) +R 8 (#7c5182) +D 4 (#06d041) +R 7 (#0eb4b2) +D 4 (#aad7d1) +R 6 (#4bb150) +D 5 (#018911) +R 9 (#8f71a0) +D 4 (#018913) +L 5 (#35c370) +D 3 (#06d721) +L 7 (#826820) +D 5 (#06d723) +L 4 (#1a5580) +U 4 (#154ba1) +L 9 (#1b1a40) +U 4 (#312983) +L 5 (#1954f0) +D 8 (#42a4c3) +L 7 (#2bcbf0) +D 6 (#3503a1) +R 7 (#758940) +D 2 (#3ecaa1) +R 8 (#386590) +D 6 (#5e4e81) +R 7 (#0e3c80) +D 5 (#26f911) +R 11 (#968190) +D 5 (#595b61) +R 6 (#6a6f80) +D 2 (#52fe41) +R 6 (#8744e0) +D 3 (#602db1) +R 2 (#8744e2) +D 10 (#0a8c31) +R 6 (#6a6f82) +D 8 (#193131) +L 6 (#5f1f00) +D 4 (#7cdd71) +L 3 (#6b3d50) +D 7 (#249321) +L 9 (#7dc2c0) +D 8 (#62d1f1) +R 9 (#44aca0) +D 4 (#904201) +L 7 (#6b7f80) +D 8 (#904203) +L 3 (#2eb8a0) +D 8 (#63f7a1) +L 4 (#493500) +D 3 (#8cc041) +L 4 (#7b1b20) +D 3 (#8b6cc1) +L 5 (#6c17a0) +D 4 (#73f141) +R 5 (#4c8490) +D 3 (#334893) +R 11 (#098a80) +D 4 (#6a78e3) +L 12 (#098a82) +D 3 (#4e3fe3) +L 4 (#0b86c0) +D 7 (#6a0593) +L 9 (#179fa0) +D 6 (#56f603) +L 2 (#15a970) +D 5 (#1d2413) +L 10 (#a5a530) +D 4 (#1427e3) +R 3 (#40f6d0) +D 7 (#11cd13) +R 6 (#4bf000) +D 4 (#0c91e3) +R 7 (#23bfe0) +D 5 (#0c91e1) +R 3 (#6a9340) +U 13 (#1df6f1) +R 4 (#7a7962) +U 3 (#6ddfe1) +R 7 (#524da2) +D 7 (#70b671) +R 7 (#4e23b2) +D 8 (#30dd71) +L 5 (#20f980) +D 4 (#a02bd1) +L 3 (#1efe40) +D 8 (#508913) +L 3 (#5a2560) +D 4 (#514333) +L 3 (#595c00) +D 9 (#514331) +L 3 (#751590) +D 7 (#508911) +L 6 (#383030) +D 8 (#637d41) +L 3 (#44eda2) +D 3 (#2d6cd1) +R 7 (#3cac72) +D 3 (#6cca11) +R 7 (#505db0) +D 3 (#21e651) +L 5 (#505db2) +D 7 (#5e1611) +L 5 (#3cac70) +U 7 (#39ca81) +L 4 (#53ed02) +D 6 (#1c6103) +L 4 (#4544c2) +U 3 (#63ec43) +L 5 (#0a7bc0) +U 7 (#410b53) +L 5 (#0a7bc2) +U 10 (#31e923) +R 4 (#5650b2) +U 8 (#60bc13) +L 4 (#6c4ed2) +U 3 (#01c071) +L 9 (#6251e0) +U 2 (#6fb8e1) +L 2 (#3e1f70) +U 6 (#4e52e1) +R 3 (#2bea02) +U 5 (#1a6363) +R 8 (#6c00f2) +U 3 (#1a6361) +L 2 (#5249a2) +U 4 (#26e541) +L 8 (#279592) +D 3 (#34d2c1) +L 4 (#6d3cc2) +D 7 (#5f0761) +L 6 (#2996f2) +U 11 (#404d91) +R 3 (#7b7b92) +U 4 (#04e471) +R 6 (#8eaea2) +U 2 (#04e473) +R 7 (#0189f2) +U 4 (#404d93) +L 4 (#1d8222) +U 2 (#408021) +L 9 (#099410) +U 3 (#62d111) +R 4 (#5f0a20) +U 5 (#215971) +R 4 (#054570) +U 7 (#562131) +R 3 (#2cc810) +U 7 (#81bbf3) +L 4 (#8380d0) +U 4 (#080873) +L 8 (#371d70) +U 2 (#89c461) +L 2 (#4910e0) +U 7 (#08fb51) +L 7 (#21af20) +D 4 (#1e4701) +L 5 (#279590) +D 2 (#63a4f1) +L 8 (#8baa52) +D 4 (#208f51) +R 6 (#0cc5a2) +D 2 (#397b91) +R 7 (#150182) +D 3 (#44cd31) +L 4 (#324f92) +D 3 (#6518a1) +L 5 (#82ed62) +D 4 (#5cb001) +L 4 (#2cadb2) +U 4 (#0c40a1) +L 13 (#4e4972) +D 4 (#3e5303) +L 8 (#191842) +U 4 (#3eba41) +L 3 (#900472) +D 4 (#3eba43) +L 8 (#188072) +D 6 (#3e5301) +R 10 (#7f8942) +D 6 (#0f5643) +R 11 (#60f2c2) +D 3 (#293e73) +R 8 (#67ab70) +U 7 (#7bd493) +R 4 (#67ab72) +D 7 (#97e8c3) +R 7 (#4bcf92) +D 2 (#4d67a3) +R 5 (#55dba0) +D 5 (#2fb9d3) +L 12 (#55dba2) +D 3 (#4a35c3) +L 3 (#5de0f0) +D 2 (#41fef3) +L 8 (#733be0) +D 5 (#3fdfb3) +L 7 (#2bcdb2) +D 4 (#692073) +L 4 (#4e7612) +U 3 (#598803) +L 12 (#56d912) +U 4 (#752383) +L 8 (#0e43f2) +U 4 (#138221) +L 7 (#276162) +U 10 (#545561) +L 4 (#7a6f62) +U 9 (#4ebfa1) +L 5 (#2edad2) +U 7 (#0427c1) +L 3 (#6722a2) +U 5 (#2cedc1) +L 3 (#0aa132) +U 7 (#6db771) +L 7 (#5feaa0) +D 7 (#04e323) +L 8 (#01f6d0) +U 4 (#2a1803) +L 6 (#767010) +U 2 (#2a1801) +L 10 (#537b60) +U 5 (#04e321) +L 6 (#16a280) +U 4 (#4edba1) +L 3 (#8f1c22) +U 6 (#30de81) +L 6 (#0df712) +U 4 (#6fb451) +L 3 (#321b02) +U 10 (#44c0c1) +L 6 (#0cbf22) +U 6 (#2dedf1) +R 2 (#645d52) +U 6 (#008341) +R 5 (#5d3e82) +U 5 (#85b221) +R 5 (#747de2) +U 5 (#0f5b41) +R 4 (#0c23e2) +U 4 (#3b9673) +R 7 (#65bf42) +U 3 (#7256d3) +R 3 (#350892) +U 6 (#aded41) +R 3 (#41e0a2) +U 3 (#69f231) +R 9 (#04bf52) +D 5 (#664b91) +R 3 (#5c5c02) +D 10 (#0efdf1) +R 4 (#5f4102) +D 4 (#43efa3) +R 5 (#5abff2) +U 8 (#3ccba3) +R 4 (#429202) +U 2 (#7cebd3) +R 6 (#429200) +U 5 (#0b7163) +R 2 (#5abff0) +U 2 (#3b0713) +R 11 (#9d9132) +U 2 (#1483d3) +R 8 (#52f672) +U 7 (#9469f1) +R 4 (#40a982) +U 4 (#04d1d1) +L 8 (#311ef2) +U 4 (#7cf7b1) +L 6 (#12ff02) +U 7 (#426fe1) +L 6 (#5d3c02) +U 5 (#4c3953) +L 10 (#101c72) +U 3 (#83b373) +L 7 (#1d9202) +U 4 (#0f4ef3) +L 5 (#1d2662) +U 5 (#24e2d3) +L 7 (#5e8242) +U 5 (#833353) +R 7 (#29d152) +U 4 (#10a5c3) +L 3 (#2027e2) +U 3 (#662453) +L 7 (#6cab80) +U 4 (#1a9013) +L 4 (#6cab82) +U 3 (#5b9d73) +L 4 (#6661c2) +U 9 (#08dc33) +L 2 (#7e9792) +U 2 (#407f13) +L 5 (#8f3792) +U 5 (#49b883) +R 6 (#060290) +U 6 (#620dd3) +R 4 (#26e8d0) +U 3 (#41fde3) +R 5 (#4c84e0) +U 7 (#1663f3) +R 4 (#797042) +U 6 (#5c6d93) +L 8 (#289052) +U 6 (#5b9c03) +L 5 (#5e5b60) +U 8 (#44baf3) +L 6 (#6c1932) +U 3 (#1ef693) +L 5 (#7757c2) +U 8 (#1522f3) +L 2 (#3564a0) +U 10 (#3e8e53) +L 3 (#370a00) +U 2 (#4f7043) +L 7 (#55b7b0) +U 7 (#8dfe91) +L 8 (#019ee0) +D 8 (#600a93) +L 6 (#1fabc0) +D 11 (#178133) +R 6 (#418080) +D 8 (#5619b3) +L 6 (#9a4e90) +D 3 (#2b6983) +L 6 (#0da050) +D 4 (#3b7653) +R 3 (#396df0) +D 6 (#4c8b43) +R 6 (#752a72) +D 4 (#726f81) +L 7 (#736dd2) +D 5 (#461241) +L 4 (#4e1ff2) +D 7 (#461243) +R 5 (#3220d2) +D 8 (#726f83) +R 6 (#185fb2) +D 4 (#489f93) +L 9 (#aced52) +D 3 (#440513) +L 2 (#5e9192) +D 6 (#11a943) +L 3 (#3ff332) +D 5 (#55e473) +L 3 (#3ff330) +D 6 (#58fa73) +L 5 (#562302) +D 4 (#60e413) +L 4 (#7457e2) +U 4 (#87c6d3) +L 11 (#3e5822) +U 6 (#1d1bc3) +R 11 (#1604c2) +U 6 (#62d593) +L 4 (#0a2e92) +U 6 (#625e71) +L 3 (#77cce2) +U 6 (#625e73) +L 5 (#3912b2) +U 4 (#3288c3) +L 8 (#1be242) +U 5 (#903ae3) diff --git a/day18/lagoon.go b/day18/lagoon.go index 40a252f..f1bab05 100644 --- a/day18/lagoon.go +++ b/day18/lagoon.go @@ -10,22 +10,30 @@ import ( ) func Run() int { - fmt.Println("hello day 18") + log.Println("hello day 18") log.Println("problem of lagoon bgins") - filename := "day18/example" + filename := "day18/input" instructions := ReadInstructionas(filename) h, w := calcHeightWidth(instructions) - field := CreateField(h, w) + log.Printf("read %d instructions", len(instructions)) - fmt.Println(field.String()) + field := CreateField(h, w) + log.Println("created field") + + // fmt.Println(field.String()) field.digByInstructions(instructions) - fmt.Println(field.String()) + // WriteToFile("borders.txt", field.String()) + // convert -size 3000x6000 xc:white -font "FreeMono" -pointsize 13 -fill black -draw @borders.txt borders.png + + // fmt.Println(field.String()) // i'll start at (0,0), let's first just dig out the thing and check result field.digInsides() - fmt.Println(field.String()) + // WriteToFile("fulldug.txt", field.String()) + // convert -size 3000x6000 xc:white -font "FreeMono" -pointsize 13 -fill black -draw @fulldug.txt fulldug.png + // fmt.Println(field.Height, field.Width) return field.countDugOut() } @@ -150,6 +158,7 @@ func (c Coord)applyDirection(d Direction) Coord { type Cell struct { IsDug bool + ToBeDug bool Walls map[Direction]string Coord Coord } @@ -187,6 +196,7 @@ func (f *Field)digByInstructions(instructions []Instruction) { f.Cells[row][col].IsDug = true for _, instruction := range instructions { + log.Printf("starting instruction %+v", instruction) for i := 0; i < instruction.Steps; i++ { runnerCoord = runnerCoord.applyDirection(instruction.Direction) row, col := f.coordToIndices(runnerCoord) @@ -197,17 +207,65 @@ func (f *Field)digByInstructions(instructions []Instruction) { } func (f *Field)String() string { - s := "\n" - for _, row := range f.Cells { + s := "text 15,15 \"" + firstNonemptyRow, lastNonemptyRow := 0,0 + seenInRows := false + firstNonemptyCol, lastNonemptyCol := 0,0 + seenInCols := false + + for i, row := range f.Cells { + seenInRow := false for _, cell := range row { if cell.IsDug { - s += "#" + seenInRow = true } else { - s += "." } } + + seenInRows = seenInRows || seenInRow + if seenInRow { + lastNonemptyRow = i + } + if !seenInRows { + firstNonemptyRow = i + } + } + + for col := 0; col < f.Width; col++ { + seenInCol := false + for row := 0; row < f.Height; row++ { + cell := f.Cells[row][col] + if cell.IsDug { + seenInCol = true + } + } + seenInCols = seenInCols || seenInCol + if seenInCol { + lastNonemptyCol = col + } + if !seenInCols { + firstNonemptyCol = col + } + } + + rowLen := lastNonemptyCol - firstNonemptyCol + 1 + for i := firstNonemptyRow; i <= lastNonemptyRow; i++ { + rowChars := make([]rune, rowLen) + for col := firstNonemptyCol; col <= lastNonemptyCol; col++ { + cell := f.Cells[i][col] + if cell.IsDug { + rowChars[col-firstNonemptyCol] = '#' + } else if cell.ToBeDug { + rowChars[col-firstNonemptyCol] = '@' + } else { + rowChars[col-firstNonemptyCol] = '.' + } + } + + s += string(rowChars) s += "\n" } + s += "\"" return s } @@ -230,7 +288,7 @@ func (f *Field)digInsides() { } else { // not a dug out cell, maybe inside and needs to be dug out if isInside { - cellPtr.IsDug = true + cellPtr.ToBeDug = true } if rightCell.IsDug { nextUpCell := f.Cells[row-1][col+1] @@ -247,10 +305,24 @@ func (f *Field)digInsides() { func (f *Field)countDugOut() (result int) { for _, row := range f.Cells { for _, cell := range row { - if cell.IsDug { + if cell.IsDug || cell.ToBeDug { result += 1 } } } return } + +func WriteToFile(filename string, content string) { + fileBorder, err := os.Create(filename) + if err != nil { + panic(err) + } + defer func(){ + if err := fileBorder.Close(); err != nil { + panic(err) + } + }() + + fileBorder.WriteString(content) +}