Skip to content

Commit 3c370cc

Browse files
committed
icons
1 parent 64f1cb9 commit 3c370cc

File tree

15 files changed

+83
-15
lines changed

15 files changed

+83
-15
lines changed

2024/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Puzzle | Stars | Langu
1111
---------------------------------------------------------------- | ----- | -----------
1212
[Day 1: Historian Hysteria](https://adventofcode.com/2024/day/1) | ⭐⭐ | [Rust](../2024/day1/day1.rs) [Python](../2024/day1/day1.py) [C](../2024/day1/day1.c) [C++](../2024/day1/day1.cpp) [Go](../2024/day1/day1.go) [Ruby](../2024/day1/day1.rb) [JS](../2024/day1/day1.js) [Bash](../2024/day1/day1.sh) [Lua](../2024/day1/day1.lua) [C#](../2024/day1/day1.cs)
1313
[Day 2: Red-Nosed Reports](https://adventofcode.com/2024/day/2) | ⭐⭐ | [Rust](../2024/day2/day2.rs) [Python](../2024/day2/day2.py) [Go](../2024/day2/day2.go)
14-
[Day 3: Mull It Over](https://adventofcode.com/2024/day/3) | ⭐⭐ | [Rust](../2024/day3/day3.rs) [Python](../2024/day3/day3.py)
14+
[Day 3: Mull It Over](https://adventofcode.com/2024/day/3) | ⭐⭐ | [Rust](../2024/day3/day3.rs) [Python](../2024/day3/day3.py) [Go](../2024/day3/day3.go)

2024/day3/day3.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// [Day 3: Mull It Over](https://adventofcode.com/2024/day/3)
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"io/ioutil"
8+
"os"
9+
"regexp"
10+
"strconv"
11+
)
12+
13+
// solve computes valid mul() operations.
14+
// If part1 is false, obey to the do()/don't() statements.
15+
func solve(data string, part1 bool) int {
16+
var enabled bool = true
17+
var totalSum int
18+
i := 0
19+
20+
re := regexp.MustCompile(`^mul\((\d+),(\d+)\)`)
21+
22+
for i < len(data) {
23+
if i+4 <= len(data) && data[i:i+4] == "do()" {
24+
enabled = true
25+
i += 4
26+
27+
} else if i+7 <= len(data) && data[i:i+7] == "don't()" {
28+
enabled = false
29+
i += 7
30+
31+
} else if i+4 <= len(data) && data[i:i+4] == "mul(" {
32+
matches := re.FindStringSubmatch(data[i:])
33+
if matches != nil {
34+
if enabled || part1 {
35+
x, _ := strconv.Atoi(matches[1])
36+
y, _ := strconv.Atoi(matches[2])
37+
totalSum += x * y
38+
}
39+
i += len(matches[0])
40+
} else {
41+
i += 4
42+
}
43+
44+
} else {
45+
i++
46+
}
47+
}
48+
49+
return totalSum
50+
}
51+
52+
func main() {
53+
54+
inputFile := "input.txt"
55+
if len(os.Args) >= 2 {
56+
inputFile = os.Args[1]
57+
}
58+
59+
data, err := ioutil.ReadFile(inputFile)
60+
if err != nil {
61+
fmt.Println("Error reading file:", err)
62+
return
63+
}
64+
65+
fmt.Println(solve(string(data), true))
66+
fmt.Println(solve(string(data), false))
67+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Made for fun 😎 and to practice Rust. Many thanks to [Eric Wastl](https://twit
1212

1313
Puzzle | Stars | Languages
1414
---------------------------------------------------------------- | ----- | -----------
15-
[Day 1: Historian Hysteria](https://adventofcode.com/2024/day/1) | ⭐⭐ | [Rust](2024/day1/day1.rs) [Python](2024/day1/day1.py) [C](2024/day1/day1.c) [C++](2024/day1/day1.cpp) [Go](2024/day1/day1.go)
16-
[Day 2: Red-Nosed Reports](https://adventofcode.com/2024/day/2) | ⭐⭐ | [Rust](2024/day2/day2.rs) [Python](2024/day2/day2.py) [Go](2024/day2/day2.go)
17-
[Day 3: Mull It Over](https://adventofcode.com/2024/day/3) | ⭐⭐ | [Rust](2024/day3/day3.rs) [Python](2024/day3/day3.py)
15+
[Day 1: Historian Hysteria](https://adventofcode.com/2024/day/1) | ⭐⭐ | [![Rust](scripts/assets/rust.png)](2024/day1/day1.rs) [![Python](scripts/assets/python.png)](2024/day1/day1.py) [![C](scripts/assets/c.png)](2024/day1/day1.c) [![C++](scripts/assets/cpp.png)](2024/day1/day1.cpp) [![Go](scripts/assets/go.png)](2024/day1/day1.go) [![Ruby](scripts/assets/ruby.png)](2024/day1/day1.rb) [![Lua](scripts/assets/lua.png)](2024/day1/day1.lua) [![JavaScript](scripts/assets/javascript.png)](2024/day1/day1.js) [![Bash](scripts/assets/bash.png)](2024/day1/day1.sh) [![Java](scripts/assets/java.png)](2024/day1/day1.java) [![C#](scripts/assets/csharp.png)](2024/day1/day1.cs)
16+
[Day 2: Red-Nosed Reports](https://adventofcode.com/2024/day/2) | ⭐⭐ | [![Rust](scripts/assets/rust.png)](2024/day2/day2.rs) [![Python](scripts/assets/python.png)](2024/day2/day2.py) [![Go](scripts/assets/go.png)](2024/day2/day2.go)
17+
[Day 3: Mull It Over](https://adventofcode.com/2024/day/3) | ⭐⭐ | [![Rust](scripts/assets/rust.png)](2024/day3/day3.rs) [![Python](scripts/assets/python.png)](2024/day3/day3.py) [![Go](scripts/assets/go.png)](2024/day3/day3.go)
1818

1919
## Paste years
2020

scripts/answers.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -659,17 +659,18 @@ def parse(_self, year, _day):
659659
stars = "⭐" * stars
660660

661661
files = []
662-
files.extend(f"[Rust]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".rs")
663-
files.extend(f"[Python]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".py")
664-
665-
files.extend(f"[C]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".c")
666-
files.extend(f"[C++]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".cpp")
667-
files.extend(f"[Go]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".go")
668-
# files.extend(f"[Ruby]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".rb")
669-
# files.extend(f"[JS]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".js")
670-
# files.extend(f"[Bash]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".sh")
671-
# files.extend(f"[Lua]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".lua")
672-
# files.extend(f"[C#]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".cs")
662+
files.extend(f"[![Rust](scripts/assets/rust.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".rs")
663+
files.extend(f"[![Python](scripts/assets/python.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".py")
664+
665+
files.extend(f"[![C](scripts/assets/c.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".c")
666+
files.extend(f"[![C++](scripts/assets/cpp.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".cpp")
667+
files.extend(f"[![Go](scripts/assets/go.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".go")
668+
files.extend(f"[![Ruby](scripts/assets/ruby.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".rb")
669+
files.extend(f"[![Lua](scripts/assets/lua.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".lua")
670+
files.extend(f"[![JavaScript](scripts/assets/javascript.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".js")
671+
files.extend(f"[![Bash](scripts/assets/bash.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".sh")
672+
files.extend(f"[![Java](scripts/assets/java.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".java")
673+
files.extend(f"[![C#](scripts/assets/csharp.png)]({year}/{f.relative_to(year_dir)})" for f in sols if f.suffix == ".cs")
673674

674675
files = " ".join(files)
675676

scripts/assets/bash.png

1.12 KB
Loading

scripts/assets/c.png

615 Bytes
Loading

scripts/assets/cpp.png

960 Bytes
Loading

scripts/assets/csharp.png

709 Bytes
Loading

scripts/assets/go.png

520 Bytes
Loading

scripts/assets/java.png

751 Bytes
Loading

0 commit comments

Comments
 (0)