diff --git a/9/go.mod b/9/go.mod new file mode 100644 index 0000000..f36eb12 --- /dev/null +++ b/9/go.mod @@ -0,0 +1,3 @@ +module day92 + +go 1.22.4 diff --git a/9/main.go b/9/main.go index e009aff..12e8e04 100644 --- a/9/main.go +++ b/9/main.go @@ -9,8 +9,8 @@ import ( ) func main() { -// file, _ := os.Open("test") - file, _ := os.Open("input") + file, _ := os.Open("test") +// file, _ := os.Open("input") defer file.Close() scanner := bufio.NewScanner(file) diskMap := []string{} @@ -20,37 +20,129 @@ func main() { } fileID := 0 blockSize := 0 + blockSizes := []int{} freeSpace := 0 + freeSpaces := []int{} blocks := []string{} for i := range diskMap { if i % 2 == 0 { blockSize, _ = strconv.Atoi(diskMap[i]) + blockSizes = append(blockSizes, blockSize) for j:=0;ji;j-- { - if blocks[j] != "." { - blocks[i] = blocks[j] - blocks[j] = "." - break +// for i := range blocks { +// if blocks[i] == "." { +// for j:=len(blocks)-1;j>i;j-- { +// if blocks[j] != "." { +// blocks[i] = blocks[j] +// blocks[j] = "." +// break +// } +// } +// } +// } +// checksum := 0 +// for i := range blocks { +// blockID, _ := strconv.Atoi(blocks[i]) +// checksum = checksum + i * blockID +// } +// fmt.Println(checksum) + fmt.Println(blocks) +// moved := []bool{} +// for i:=0;i=0;id-- { +// for j:=0;j=0;id-- { + idPositions := findIDpositions(blocks, id) + for i:=0;i