aoc_utils 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/aoc_utils.rb +34 -2
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf1755d4a9c53efe1b50f38047add2e446268b87e2e4233861fd44af9fcd9137
4
- data.tar.gz: da702aaf7e05bccc4cdba5f3da55594e09ba6c404a4a8c28ec71ed02026a7dff
3
+ metadata.gz: 91281ea705349ee1f046ff24cc48e6f888c9b26859661127b17ec41adf45aa37
4
+ data.tar.gz: 735ae0c912af26338c320a317fccb835dabfc1b7120ec40ae9f3db28d5db5018
5
5
  SHA512:
6
- metadata.gz: 6f91aa0cb65a4d5c846432703ee26dd59c5088707f16276754cadf8e4a3279cf035311cc3fc29ce95b478c3f5d586ea5b333367aed779812c26c569053f01b70
7
- data.tar.gz: 11b070763fc4f304cb1c308e39fbc95e3caab046b44c2b8b8e0f114c0167d4f3e428fbcbe84395f555d7556ce10c8bd45df49ee0ac25e8a2a06f6e3ad71638d6
6
+ metadata.gz: e4653b0d8fee196d782516f640e5936b8dac44529736c241634f4926606339c7acb1cc9ae1ccf5b3964d24a0f98d500bc50e960c934db77df3e2251ac10cfef1
7
+ data.tar.gz: 87e45458fb2568de4d758640c3fd94ada91380c62fca519e7215cb2c93014507f6e4bc406628bf104b10aa3e88bb871186d93e2877d835f9e935cded20bed4c2
data/lib/aoc_utils.rb CHANGED
@@ -49,7 +49,7 @@ module AocUtils
49
49
  when "Integer"
50
50
  part1 = part1.map { |line| line.scan(/-?\d+/).map(&:to_i) }
51
51
  when "String"
52
- part1 = part1.map { |string| string.split(",").map(&:strip) }
52
+ part1 = part1.map { |string| string.split(",").map(&:strip) }.flatten
53
53
  when "Char"
54
54
  part1.strip!
55
55
  part1 = part1.map(&:chars)
@@ -60,11 +60,43 @@ module AocUtils
60
60
  when "Integer"
61
61
  part2 = part2.map { |line| line.scan(/-?\d+/).map(&:to_i) }
62
62
  when "String"
63
- part2 = part2.map { |string| string.split(",").map(&:strip) }
63
+ part2 = part2.map { |string| string.split(",").map(&:strip) }.flatten
64
64
  when "Char"
65
65
  part2.strip!
66
66
  part2 = part2.map(&:chars)
67
67
  end
68
68
  [part1, part2]
69
69
  end
70
+
71
+ # provides methods for working with a maze. The maze is represented as a 2D array of characters where '#' represents a wall and '.' represents an empty space
72
+ class MazeUtils
73
+
74
+ def self.find_char(maze)
75
+ maze.each_with_index do |row, y|
76
+ row.each_with_index do |cell, x|
77
+ return [x, y] if yield(cell)
78
+ end
79
+ end
80
+ end
81
+
82
+ def self.calculate_distance_to_point(maze, point)
83
+ maze[point[1]][point[0]] = 0
84
+ queue = [point]
85
+ until queue.empty?
86
+ current = queue.shift
87
+ value = maze[current[1]][current[0]]
88
+ [[-1, 0], [1, 0], [0, -1], [0, 1]].each do |direction|
89
+ new_coordinate = [current[0] + direction[0], current[1] + direction[1]]
90
+ if new_coordinate[0] < 0 || new_coordinate[0] >= maze[0].length || new_coordinate[1] < 0 || new_coordinate[1] >= maze.length
91
+ next
92
+ end
93
+ if maze[new_coordinate[1]][new_coordinate[0]] == "."
94
+ maze[new_coordinate[1]][new_coordinate[0]] = value + 1
95
+ queue.push(new_coordinate)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
70
101
  end
102
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aoc_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lennard Clicque
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-20 00:00:00.000000000 Z
11
+ date: 2025-10-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A collection of utility methods for Advent of Code
14
14
  email: l.clicque@gmail.com
@@ -18,7 +18,8 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/aoc_utils.rb
20
20
  homepage: https://rubygems.org/gems/aoc_utils
21
- licenses: []
21
+ licenses:
22
+ - MIT
22
23
  metadata: {}
23
24
  post_install_message:
24
25
  rdoc_options: []