initialise

This commit is contained in:
Javier-Orestis MANTZIOS
2025-01-07 10:39:37 +02:00
commit 108f50e8ea
25 changed files with 5534 additions and 0 deletions

50
8/input Normal file
View File

@@ -0,0 +1,50 @@
...........V..................b.g.................
..................................g...............
.............................c....................
............T........Z.......P....................
.x........................VP......................
..........................PH......................
.................H.....Z.......g.R................
......f............T.V....b......A................
......................P...........................
.......f..................A.............R.........
........x..............T.......l..H.....A.c.......
..k..x..............Z.............................
........5....S...............0.A..................
.............N....L...............................
.f............................T........s.....N....
..................l..........bH.......tc.R..N.....
......Z...6......n......l...k.N...0...............
...........g....S......l.r.................t..s...
..L................b.......K..t...................
................5....n........0.............c.....
.....L......n............................E........
.k.......L................m.....................Es
..............St.....5....Rm......................
............6..5...................3...0..........
...........k.................W........3...........
................n......K...E....2S..........3.....
....................................E....Q........
..........M.....x...............K.................
..h.............................1.................
.6............z..............4...e.........WY....y
........f............a.......Y..y...s.............
...h............r.............v....m..............
.....h.................v....m.....Y.Q.....W3......
.........................Yq....Q.................7
.........6..............7.................9.......
...................X..........y..q.....2..........
............r..............q.....y...........7.8..
..B..............M....4............9..............
...1.......M...X.......CGzp...4..B...2..K.........
.....................z...v....Q.....8...........9.
B.......X.F....rM...v...............2...8..D......
h1..............................7..D.....8....d...
...............F.....................9D....4....d.
..........a......p............F.........W.D......d
.........................G..C...........q.........
...B..................................C...........
.........w..........z....p.....................e..
.a............G....w........p........F........e...
........a...w.....................................
........w...............XC.......G................

93
8/main.go Normal file
View File

@@ -0,0 +1,93 @@
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
)
func findAntennas(layout [][]string, antenna string) [][]int {
antenaPositions := [][]int{}
for i := range layout {
for j := range layout[i] {
if layout[i][j] == antenna {
antenaPositions = append(antenaPositions, []int{i,j})
}
}
}
return antenaPositions
}
func calcAntiNodes(layout [][]string, node1, node2 []int) [][]int {
x := node1[0] - node2[0]
y := node1[1] - node2[1]
antinodes := [][]int{}
for i:=0;i<len(layout);i++ {
antinode1 := []int{node1[0] + i*x, node1[1] + i*y}
antinode2 := []int{node2[0] - i*x, node2[1] - i*y}
if ! (antinode1[0] >= 0 && antinode1[1] >= 0 && antinode1[0] < len(layout) && antinode1[1] < len(layout)) {
antinode1 = []int{}
}
if ! (antinode2[0] >= 0 && antinode2[1] >= 0 && antinode2[0] < len(layout) && antinode2[1] < len(layout)) {
antinode2 = []int{}
}
if len(antinode1) > 0 {
antinodes = append(antinodes, antinode1)
}
if len(antinode2) >0 {
antinodes = append(antinodes, antinode2)
}
}
return antinodes
}
func main() {
// file, _ := os.Open("test")
file, _ := os.Open("input")
defer file.Close()
scanner := bufio.NewScanner(file)
regexAntenna := regexp.MustCompile(`[^.]`)
antennas := []string{}
layout := [][]string{}
for scanner.Scan() {
line := scanner.Text()
layout = append(layout, strings.Split(line, ""))
// //fmt.Println(line)
foundAntennas := regexAntenna.FindAllString(line, -1)
if len(foundAntennas) > 0 {
antennas = append(antennas, foundAntennas...)
}
}
antennaMap := make(map[string][][]int)
for _, antenna := range antennas {
// //fmt.Println(antenna)
key := antenna
antennaMap[key] = findAntennas(layout,antenna)
}
//fmt.Println(antennaMap)
antinodelist := [][]int{}
for _,v := range antennaMap {
//fmt.Println("key: ", k, "value: ", v)
for i:=0;i<len(v);i++ {
for j:=0;j<len(v);j++ {
if j>i {
//fmt.Println(v[i],v[j])
antinodes := calcAntiNodes(layout, v[i], v[j])
antinodelist = append(antinodelist, antinodes...)
}
}
}
}
//fmt.Println(antinodelist)
antinodeMap := make(map[[2]int]int)
for i := range antinodelist {
if len(antinodelist[i]) > 0 {
key := [2]int{antinodelist[i][0], antinodelist[i][1]}
antinodeMap[key]++
}
}
fmt.Println(len(antinodeMap))
}

0
8/temp Normal file
View File

12
8/test Normal file
View File

@@ -0,0 +1,12 @@
............
........0...
.....0......
.......0....
....0.......
......A.....
............
............
........A...
.........A..
............
............