mirror of
https://github.com/fredrikr79/advent_of_code.git
synced 2026-07-18 00:10:29 +02:00
Compare commits
6 Commits
cf64d5950e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 643f175635 | |||
| 4ad82ea6cb | |||
| 7552d8dbdb | |||
| c9a62f274c | |||
| 16684fea02 | |||
| 87457e0a92 |
@@ -0,0 +1,15 @@
|
|||||||
|
(def example-input `11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124`)
|
||||||
|
|
||||||
|
(defn mapi "immutable map" [f xs] (slice (map f xs)))
|
||||||
|
|
||||||
|
(defn parse-input [input]
|
||||||
|
(mapi |(mapi parse (string/split "-" $))
|
||||||
|
(string/split "," input)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn solve/1 [data]
|
||||||
|
(map (fn [[l r]]
|
||||||
|
(range l r))
|
||||||
|
data))
|
||||||
|
|
||||||
|
(pp (solve/1 (parse-input example-input)))
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
all:
|
||||||
|
./main.nu
|
||||||
Executable
+31
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env nu
|
||||||
|
def part-1 [parsed] {
|
||||||
|
$parsed
|
||||||
|
| par-each {
|
||||||
|
|row| where {|x| into string
|
||||||
|
| split chars
|
||||||
|
| take (($in | length) // 2)
|
||||||
|
| ($in | str join) + ($in | str join)
|
||||||
|
| try {into int} catch {0}
|
||||||
|
| $in == $x
|
||||||
|
}
|
||||||
|
} | flatten | math sum
|
||||||
|
}
|
||||||
|
|
||||||
|
def part-2 [parsed] {
|
||||||
|
$parsed
|
||||||
|
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = open input
|
||||||
|
let parsed = $input
|
||||||
|
| str trim
|
||||||
|
| lines
|
||||||
|
| str join
|
||||||
|
| split row ','
|
||||||
|
| split column '-'
|
||||||
|
| rename l u
|
||||||
|
| into int l u
|
||||||
|
| each {|row| $row.l..$row.u}
|
||||||
|
|
||||||
|
part-2 ($input | str trim | split row ',' | split column '-' | rename l u | into int l u)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
162,817,812
|
||||||
|
57,618,57
|
||||||
|
906,360,560
|
||||||
|
592,479,940
|
||||||
|
352,342,300
|
||||||
|
466,668,158
|
||||||
|
542,29,236
|
||||||
|
431,825,988
|
||||||
|
739,650,466
|
||||||
|
52,470,668
|
||||||
|
216,146,977
|
||||||
|
819,987,18
|
||||||
|
117,168,530
|
||||||
|
805,96,715
|
||||||
|
346,949,466
|
||||||
|
970,615,88
|
||||||
|
941,993,340
|
||||||
|
862,61,35
|
||||||
|
984,92,344
|
||||||
|
425,690,689
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
(defn magnitude [vector]
|
||||||
|
(math/sqrt (sum (map |(* $ $) vector))))
|
||||||
|
|
||||||
|
(defn straight-line [v1 v2]
|
||||||
|
(magnitude (map - v1 v2)))
|
||||||
|
|
||||||
|
(with [f (file/open "2025/8/ex_input")]
|
||||||
|
(def parsed (freeze (map
|
||||||
|
|(map parse (string/split "," (string/trim $)))
|
||||||
|
(file/lines f))))
|
||||||
|
(loop [i :range [0 (length parsed)]
|
||||||
|
:after (print)
|
||||||
|
j :range [0 i]]
|
||||||
|
(let [v1 (get parsed i)
|
||||||
|
v2 (get parsed j)]
|
||||||
|
(pp (straight-line v1 v2)))))
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package day_8
|
||||||
|
|
||||||
|
import "core:fmt"
|
||||||
|
import "core:strconv"
|
||||||
|
import "core:strings"
|
||||||
|
|
||||||
|
input :: cast(string)#load("../ex_input")
|
||||||
|
|
||||||
|
Pos :: [3]int
|
||||||
|
|
||||||
|
parse :: proc(input: string) -> (res: []Pos, ok: bool) {
|
||||||
|
data: [dynamic]Pos
|
||||||
|
for line in strings.split_lines(strings.trim_space(input)) {
|
||||||
|
raw_pos := strings.split(line, ",")
|
||||||
|
pos: Pos
|
||||||
|
for &v, i in pos {
|
||||||
|
v = strconv.parse_int(raw_pos[i]) or_return
|
||||||
|
}
|
||||||
|
append(&data, pos)
|
||||||
|
}
|
||||||
|
return data[:], true
|
||||||
|
}
|
||||||
|
|
||||||
|
solve_1 :: proc(data: []Pos) -> int {
|
||||||
|
edges: map[Pos]Pos
|
||||||
|
for p1 in data {
|
||||||
|
for p2 in data {
|
||||||
|
if p1 == p2 do continue
|
||||||
|
if p1 not_in edges do edges[p1] = p2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.println(edges)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
main :: proc() {
|
||||||
|
data, ok := parse(input)
|
||||||
|
if !ok do fmt.eprintln("failed to parse")
|
||||||
|
fmt.println(solve_1(data))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user