Switching pcs

This commit is contained in:
Brian Buller 2018-12-16 07:26:17 +00:00
parent 50254aa2c1
commit 663e19ba54
5 changed files with 1154 additions and 0 deletions

103
2018/day23/day23.go Normal file
View File

@ -0,0 +1,103 @@
package main
import (
"bufio"
"fmt"
"log"
"math"
"os"
"strconv"
"strings"
)
var collective *Collective
func main() {
input := stdinToStringSlice()
collective = &Collective{}
for _, v := range input {
collective.bots = append(collective.bots, NewBot(v))
}
part1()
}
func part1() {
s := collective.strongest()
fmt.Println("= Part 1 =")
fmt.Println(len(collective.inRange(s)))
}
func part2() {
finder := &Bot{}
}
type Collective struct {
bots []*Bot
}
func (c *Collective) inRange(b *Bot) []*Bot {
var ret []*Bot
for _, v := range c.bots {
if c.distance(b, v) <= b.radius {
ret = append(ret, v)
}
}
return ret
}
func (c *Collective) strongest() *Bot {
strongest := c.bots[0]
for _, v := range c.bots {
if v.radius > strongest.radius {
strongest = v
}
}
return strongest
}
func (c *Collective) distance(b1, b2 *Bot) int {
xs := math.Abs(float64(b1.x) - float64(b2.x))
ys := math.Abs(float64(b1.y) - float64(b2.y))
zs := math.Abs(float64(b1.z) - float64(b2.z))
return int(xs + ys + zs)
}
type Bot struct {
x, y, z int
radius int
}
func NewBot(args string) *Bot {
pts := strings.Split(args, ", ")
pos := strings.Split(pts[0][5:len(pts[0])-1], ",")
r := strings.Split(pts[1], "=")[1]
return &Bot{
x: atoi(pos[0]),
y: atoi(pos[1]),
z: atoi(pos[2]),
radius: atoi(r),
}
}
func (b *Bot) string() string {
return fmt.Sprintf("(%d,%d,%d : %d)", b.x, b.y, b.z, b.radius)
}
func stdinToStringSlice() []string {
var input []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = append(input, scanner.Text())
}
return input
}
func atoi(i string) int {
var ret int
var err error
if ret, err = strconv.Atoi(i); err != nil {
log.Fatal("Invalid Atoi")
}
return ret
}

1000
2018/day23/input Normal file

File diff suppressed because it is too large Load Diff

9
2018/day23/testinput Normal file
View File

@ -0,0 +1,9 @@
pos=<0,0,0>, r=4
pos=<1,0,0>, r=1
pos=<4,0,0>, r=3
pos=<0,2,0>, r=1
pos=<0,5,0>, r=3
pos=<0,0,3>, r=1
pos=<1,1,1>, r=1
pos=<1,1,2>, r=1
pos=<1,3,1>, r=1

19
2018/day24/day24.go Normal file
View File

@ -0,0 +1,19 @@
package main
import "fmt"
const ()
func main() {
fmt.Println("vim-go")
}
type AttackType int
type Army struct {
units int
hp int
weaknesses []string
strength int
dam
}

23
2018/day24/input Normal file
View File

@ -0,0 +1,23 @@
Immune System:
2991 units each with 8084 hit points (weak to fire) with an attack that does 19 radiation damage at initiative 11
4513 units each with 3901 hit points (weak to slashing; immune to bludgeoning, radiation) with an attack that does 7 bludgeoning damage at initiative 12
5007 units each with 9502 hit points (immune to bludgeoning; weak to fire) with an attack that does 16 fire damage at initiative 2
2007 units each with 5188 hit points (weak to radiation) with an attack that does 23 cold damage at initiative 9
1680 units each with 1873 hit points (immune to bludgeoning; weak to radiation) with an attack that does 10 bludgeoning damage at initiative 10
1344 units each with 9093 hit points (immune to bludgeoning, cold; weak to radiation) with an attack that does 63 cold damage at initiative 16
498 units each with 2425 hit points (immune to fire, bludgeoning, cold) with an attack that does 44 slashing damage at initiative 3
1166 units each with 7295 hit points with an attack that does 56 bludgeoning damage at initiative 8
613 units each with 13254 hit points (immune to radiation, cold, fire) with an attack that does 162 radiation damage at initiative 15
1431 units each with 2848 hit points (weak to radiation) with an attack that does 19 cold damage at initiative 1
Infection:
700 units each with 47055 hit points (weak to fire; immune to slashing) with an attack that does 116 fire damage at initiative 14
2654 units each with 13093 hit points (weak to radiation) with an attack that does 8 radiation damage at initiative 19
5513 units each with 18026 hit points (immune to radiation; weak to slashing) with an attack that does 6 slashing damage at initiative 20
89 units each with 48412 hit points (weak to cold) with an attack that does 815 radiation damage at initiative 17
2995 units each with 51205 hit points (weak to cold) with an attack that does 28 slashing damage at initiative 7
495 units each with 21912 hit points with an attack that does 82 cold damage at initiative 13
2911 units each with 13547 hit points with an attack that does 7 slashing damage at initiative 18
1017 units each with 28427 hit points (immune to fire) with an attack that does 52 fire damage at initiative 4
2048 units each with 29191 hit points (weak to bludgeoning) with an attack that does 22 bludgeoning damage at initiative 6
1718 units each with 15725 hit points (immune to cold) with an attack that does 18 slashing damage at initiative 5