I realized having to host this potentially indefinitely might not be the best idea, so I am going to shut down this gitea instance eventually.
You’ll have time, at least until the end of 2022, probably longer, but please just get all your stuff somewhere safe in case we ever disappear.

Day20 Part2 WIP (2)

master
Karl Spickermann 2 years ago
parent ce5d071d3c
commit e49ef85eba
  1. 16
      .idea/workspace.xml
  2. 103
      day20/day20.go

@ -324,26 +324,26 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="739" y="287" key="FileChooserDialogImpl/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1607278759015" />
<state width="1171" height="347" key="GridCell.Tab.0.bottom" timestamp="1608491816624">
<state width="1170" height="347" key="GridCell.Tab.0.bottom" timestamp="1608495597577">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.bottom/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629475" />
<state width="1171" height="347" key="GridCell.Tab.0.bottom/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608491816624" />
<state width="1171" height="347" key="GridCell.Tab.0.center" timestamp="1608491816624">
<state width="1170" height="347" key="GridCell.Tab.0.bottom/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608495597577" />
<state width="1170" height="347" key="GridCell.Tab.0.center" timestamp="1608495597577">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.center/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629474" />
<state width="1171" height="347" key="GridCell.Tab.0.center/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608491816624" />
<state width="1171" height="347" key="GridCell.Tab.0.left" timestamp="1608491816624">
<state width="1170" height="347" key="GridCell.Tab.0.center/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608495597577" />
<state width="1170" height="347" key="GridCell.Tab.0.left" timestamp="1608495597577">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.left/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629474" />
<state width="1171" height="347" key="GridCell.Tab.0.left/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608491816624" />
<state width="1171" height="347" key="GridCell.Tab.0.right" timestamp="1608491816624">
<state width="1170" height="347" key="GridCell.Tab.0.left/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608495597577" />
<state width="1170" height="347" key="GridCell.Tab.0.right" timestamp="1608495597577">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.right/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629475" />
<state width="1171" height="347" key="GridCell.Tab.0.right/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608491816624" />
<state width="1170" height="347" key="GridCell.Tab.0.right/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608495597577" />
<state x="782" y="240" key="RollbackChangesDialog" timestamp="1608474837005">
<screen x="0" y="0" width="1920" height="1040" />
</state>

@ -3,6 +3,7 @@ package main
import (
"AoC2020/helper"
"fmt"
"math"
"os"
"regexp"
"strconv"
@ -46,45 +47,75 @@ func main() {
product *= key
}
fmt.Println(product)
fmt.Println(tilesWithNeighbours[1951])
var picture = make(map[[2]int]int)
picture = getPictureStep(1951,tilesWithNeighbours,[]int{},picture,[2]int{0,0})
fmt.Println(picture)
picture = getPictureStep(1951,tilesWithNeighbours,[]int{},picture)
}
func getPicture(corners map[int]tile, allTiles map[int]tile) map[[2]int]int {
var picture = make(map[[2]int]int)
//len := math.Sqrt(float64(len(allTiles)))
fmt.Printf("HI %v \n", getSomeTile(corners))
currentTileId := 1951
currentTile := corners[currentTileId]
picture[[2]int{0,0}] = currentTileId
fmt.Println(currentTile.neighbourID)
fmt.Println(currentTile.edges)
printPicture(currentTile.picture)
return picture
}
func getPictureStep(currentTile int,allTiles map[int]tile,visitedTiles []int, picture map[[2]int]int,position [2]int) map[[2]int]int{
for len(visitedTiles) < len(allTiles){
func getPictureStep(currentTile int,allTiles map[int]tile,visitedTiles []int, picture map[[2]int]int) map[[2]int]int{
lenght := int(math.Sqrt(float64(len(allTiles))))
position := [2]int{0,lenght}
for allTiles[currentTile].neighbourID[1] != 0 || allTiles[currentTile].neighbourID[2] != 0{
allTiles[currentTile] = rotate(allTiles[currentTile])
fmt.Println(allTiles[currentTile])
}
fmt.Println(allTiles[currentTile])
for len(visitedTiles) < 2{
picture[position] = currentTile
visitedTiles = append(visitedTiles,currentTile)
nextTile := 0
for i, val := range allTiles[currentTile].neighbourID {
if val != 0 && !contains(val,visitedTiles){
nextTile = val
switch i {
case 0: position = [2]int{position[0],position[1]+1}
case 1: position = [2]int{position[0]+1,position[1]}
case 2: position = [2]int{position[0],position[1]-1}
case 3: position = [2]int{position[0]-1,position[1]}
}
}
}
currentTile = nextTile
nextPosition, _ := getNextPosition(position,lenght,picture)
//nextTileId, _ := getNextTile(allTiles[currentTile].edges[edge],allTiles,currentTile)
position = nextPosition
}
return picture
}
func getNextPosition(position [2]int, length int, picture map[[2]int]int) ([2]int, int) {
if (position[1]+1) < length && picture[[2]int{position[0],position[1]+1}] == 0 {
return [2]int{position[0],position[1]+1}, 0
}
if (position[0]-1) > 0 && picture[[2]int{position[0]-1,position[1]}] == 0 {
return [2]int{position[0]-1,position[1]}, 3
}
if (position[1]-1) > 0 && picture[[2]int{position[0],position[1]-1}] == 0 {
return [2]int{position[0],position[1]-1}, 2
}
if (position[0]+1) < 0 && picture[[2]int{position[0]+1,position[1]}] == 0 {
return [2]int{position[0]+1,position[1]}, 1
}
return position, -1
}
func getNextTile(edge string, allTiles map[int]tile, currentTile int) (int, tile){
var newTile tile
for id, tile := range allTiles{
if id != currentTile {
if stringContains(edge, tile.edges[:]) {
return id, tile
}
newTile = flip(tile, 0)
if stringContains(edge, newTile.edges[:]) {
return id, tile
}
newTile = flip(tile, 1)
if stringContains(edge, newTile.edges[:]) {
return id, tile
}
}
}
return 0,tile{}
}
func contains(elem int, array []int) bool{
for _, val := range array{
if val == elem{
@ -94,6 +125,15 @@ func contains(elem int, array []int) bool{
return false
}
func stringContains(elem string, array []string) bool{
for _, val := range array{
if val == elem{
return true
}
}
return false
}
func getSomeTile(m map[int]tile) int {
for k := range m {
return k
@ -124,6 +164,7 @@ func rotate(tile tile) tile{
for i,row := range newPicture {
tile.picture[i] = string(row[:])
}
tile = setEdges(tile)
return tile
}
@ -132,7 +173,7 @@ func rotate(tile tile) tile{
func flip(tile tile, direction int) tile{
var newPicture []string
if direction == 0{
for i := len(tile.picture); i >= 0; i--{
for i := len(tile.picture)-1; i >= 0; i--{
newPicture = append(newPicture,tile.picture[i])
}
}
@ -141,7 +182,10 @@ func flip(tile tile, direction int) tile{
newPicture = append(newPicture,reverse(val))
}
}
printPicture(newPicture)
newEdges := getAllPossibleEdgesForFlippedTile(tile,direction)
for i:= 0; i < len(tile.edges); i++{
tile.edges[i] = newEdges[i]
}
tile.picture = newPicture
return tile
}
@ -166,7 +210,20 @@ func getTile(input string) (int, tile) {
}
r, _ := regexp.Compile("[0-9]{4}")
number, _ := strconv.Atoi(r.FindString(tilesRow[0]))
return number, tile{[4]int{},edges, tilesRow[1:]}
tile := tile{[4]int{},edges, tilesRow[1:]}
return number, setEdges(tile)
}
func setEdges(tile tile)tile{
var newEdges [4]string
newEdges[0] = tile.picture[0]
newEdges[2] = tile.picture[len(tile.picture)-1]
for _, val := range tile.picture {
newEdges[3] = newEdges[3]+val[0:1]
newEdges[1] = newEdges[1]+val[len(val)-1:]
}
tile.edges = newEdges
return tile
}
func getAllPossibleEdgesForTile(tile tile, direction int) []string{

Loading…
Cancel
Save