aoc_utils 0.1.3 → 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 +39 -5
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4670d22399c334352f749fb796e8c716c744f61f9f2e72bf5b29f42c8bfe5085
4
- data.tar.gz: 3aae281d8b3dc3f79d9ddf7a5aec236ddeb4e32b5c4dce69d703b8ed0ff1d489
3
+ metadata.gz: 91281ea705349ee1f046ff24cc48e6f888c9b26859661127b17ec41adf45aa37
4
+ data.tar.gz: 735ae0c912af26338c320a317fccb835dabfc1b7120ec40ae9f3db28d5db5018
5
5
  SHA512:
6
- metadata.gz: 3ebf25e5a9fd9456e7e6a31d7c97a1b956fecf654252639cf8ce266fe01c4d1d58ef81740145a03f387779e97802069f26ee42ea0a435af22b419bbe1f815883
7
- data.tar.gz: 852c5342561f289945ec55039ed0ea236fab3797e9cb3f6223f0cdb9fa82cca8d17cdd5feece379efbdd7acce0d8fc25450b7a0eba894f88ffa76a32b882f1bc
6
+ metadata.gz: e4653b0d8fee196d782516f640e5936b8dac44529736c241634f4926606339c7acb1cc9ae1ccf5b3964d24a0f98d500bc50e960c934db77df3e2251ac10cfef1
7
+ data.tar.gz: 87e45458fb2568de4d758640c3fd94ada91380c62fca519e7215cb2c93014507f6e4bc406628bf104b10aa3e88bb871186d93e2877d835f9e935cded20bed4c2
data/lib/aoc_utils.rb CHANGED
@@ -15,11 +15,11 @@ module AocUtils
15
15
 
16
16
  # extracts all strings from the specified file
17
17
  # @param filename [String] the name of the file to read from
18
- # @return [Array<String>] an array of all the lines read from the file as strings with no leading or trailing whitespace
18
+ # @return [Array<String>] an array of all the lines read from the file as an array of strings with no leading or trailing whitespace split by commas in the original file
19
19
  def self.read_strings(filename)
20
20
  strings = []
21
21
  File.open(filename).each_line do |line|
22
- strings << line.strip
22
+ strings << line.strip.split(",").map(&:strip)
23
23
  end
24
24
  strings
25
25
  end
@@ -49,9 +49,10 @@ 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(&:strip)
52
+ part1 = part1.map { |string| string.split(",").map(&:strip) }.flatten
53
53
  when "Char"
54
- part1 = part1.map(&:strip.chars)
54
+ part1.strip!
55
+ part1 = part1.map(&:chars)
55
56
  else
56
57
  raise "Invalid datatype"
57
58
  end
@@ -59,10 +60,43 @@ module AocUtils
59
60
  when "Integer"
60
61
  part2 = part2.map { |line| line.scan(/-?\d+/).map(&:to_i) }
61
62
  when "String"
62
- part2 = part2.map(&:strip)
63
+ part2 = part2.map { |string| string.split(",").map(&:strip) }.flatten
63
64
  when "Char"
65
+ part2.strip!
64
66
  part2 = part2.map(&:chars)
65
67
  end
66
68
  [part1, part2]
67
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
68
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.3
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-17 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: []