aoc_utils 0.1.5 → 0.1.7

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 +5 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf1755d4a9c53efe1b50f38047add2e446268b87e2e4233861fd44af9fcd9137
4
- data.tar.gz: da702aaf7e05bccc4cdba5f3da55594e09ba6c404a4a8c28ec71ed02026a7dff
3
+ metadata.gz: 97ef492a117091eda00920c4e60c43df387d60a498028d8a4040b5b785cb4c99
4
+ data.tar.gz: 1834bc6d06f53bbb1636516a6db1fc1c11883e65de57e01d89185b9b4e054dcb
5
5
  SHA512:
6
- metadata.gz: 6f91aa0cb65a4d5c846432703ee26dd59c5088707f16276754cadf8e4a3279cf035311cc3fc29ce95b478c3f5d586ea5b333367aed779812c26c569053f01b70
7
- data.tar.gz: 11b070763fc4f304cb1c308e39fbc95e3caab046b44c2b8b8e0f114c0167d4f3e428fbcbe84395f555d7556ce10c8bd45df49ee0ac25e8a2a06f6e3ad71638d6
6
+ metadata.gz: 8735386433707f537a2575088b1cab91f9c203e188fbd1fe43dd351875b556984f011429585b65a2462fd4dea69c87fca84d5f7f9e5573a9033b7d2c6588a455
7
+ data.tar.gz: 399474e872d895f5a5ebf4427e65139d691e07b11e01bf284b79fe4409912d0bd131b7a2b894f1ac68ede044bad6e543aec5aaede5adedec293140eb0c6e3dc9
data/lib/aoc_utils.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # Desc: Utility functions for Advent of Code problems
2
2
  module AocUtils
3
+
4
+
3
5
  # extracts all integers from the specified file
4
6
  # @param filename [String] the name of the file to read from
5
7
  # @param other_characters [Array<String>] will save the first non integer character in the line for further usage
@@ -44,14 +46,14 @@ module AocUtils
44
46
  lines = File.open(filename).readlines.map(&:strip)
45
47
  index = lines.index("")
46
48
  part1 = lines[0...index]
47
- part2 = lines[(index + 1)..-1]
49
+ part2 = lines[(index + 1)..]
48
50
  case datatype1
49
51
  when "Integer"
50
52
  part1 = part1.map { |line| line.scan(/-?\d+/).map(&:to_i) }
51
53
  when "String"
52
- part1 = part1.map { |string| string.split(",").map(&:strip) }
54
+ part1 = part1.map { |string| string.split(",").map(&:strip) }.flatten
53
55
  when "Char"
54
- part1.strip!
56
+ part1.map!(&:strip)
55
57
  part1 = part1.map(&:chars)
56
58
  else
57
59
  raise "Invalid datatype"
@@ -60,11 +62,43 @@ module AocUtils
60
62
  when "Integer"
61
63
  part2 = part2.map { |line| line.scan(/-?\d+/).map(&:to_i) }
62
64
  when "String"
63
- part2 = part2.map { |string| string.split(",").map(&:strip) }
65
+ part2 = part2.map { |string| string.split(",").map(&:strip) }.flatten
64
66
  when "Char"
65
- part2.strip!
67
+ part2.map!(&:strip)
66
68
  part2 = part2.map(&:chars)
67
69
  end
68
70
  [part1, part2]
69
71
  end
72
+
73
+ # 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
74
+ class MazeUtils
75
+
76
+ def self.find_char(maze)
77
+ maze.each_with_index do |row, y|
78
+ row.each_with_index do |cell, x|
79
+ return [x, y] if yield(cell)
80
+ end
81
+ end
82
+ end
83
+
84
+ def self.calculate_distance_to_point(maze, point)
85
+ maze[point[1]][point[0]] = 0
86
+ queue = [point]
87
+ until queue.empty?
88
+ current = queue.shift
89
+ value = maze[current[1]][current[0]]
90
+ [[-1, 0], [1, 0], [0, -1], [0, 1]].each do |direction|
91
+ new_coordinate = [current[0] + direction[0], current[1] + direction[1]]
92
+ if new_coordinate[0] < 0 || new_coordinate[0] >= maze[0].length || new_coordinate[1] < 0 || new_coordinate[1] >= maze.length
93
+ next
94
+ end
95
+ if maze[new_coordinate[1]][new_coordinate[0]] == "."
96
+ maze[new_coordinate[1]][new_coordinate[0]] = value + 1
97
+ queue.push(new_coordinate)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
70
103
  end
104
+
metadata CHANGED
@@ -1,14 +1,13 @@
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lennard Clicque
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: A collection of utility methods for Advent of Code
14
13
  email: l.clicque@gmail.com
@@ -18,9 +17,9 @@ extra_rdoc_files: []
18
17
  files:
19
18
  - lib/aoc_utils.rb
20
19
  homepage: https://rubygems.org/gems/aoc_utils
21
- licenses: []
20
+ licenses:
21
+ - MIT
22
22
  metadata: {}
23
- post_install_message:
24
23
  rdoc_options: []
25
24
  require_paths:
26
25
  - lib
@@ -35,8 +34,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
35
34
  - !ruby/object:Gem::Version
36
35
  version: '0'
37
36
  requirements: []
38
- rubygems_version: 3.5.22
39
- signing_key:
37
+ rubygems_version: 3.7.2
40
38
  specification_version: 4
41
39
  summary: A collection of utility methods for Advent of Code
42
40
  test_files: []