aoc_rb_helpers 0.0.1
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.
- checksums.yaml +7 -0
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.github/workflows/tests.yml +51 -0
- data/.gitignore +20 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/aoc_rb_helpers.gemspec +28 -0
- data/lib/aoc_rb_helpers/aoc_input.rb +55 -0
- data/lib/aoc_rb_helpers/solution/input_handling.rb +8 -0
- data/lib/aoc_rb_helpers/version.rb +3 -0
- data/lib/aoc_rb_helpers.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 87b50db9a3acbc96dbf8cb70e3a3fa2f3e1341166616c3e9c29a53b6d9994201
|
4
|
+
data.tar.gz: 109fc954d7f8ec4d396ee76f51f22bb0289aed2ee68c2e605898c7204049c079
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c03ddeaafa12bb07fd9c87a2d23f11d18edf593ba3ea4390dbea32d5322d0e77e1d0662e08062729f978c1cfc4e77c7437f3b9a06bb46b61bb3a876865577dbd
|
7
|
+
data.tar.gz: 204a9d87b4eb34b6b9ae37875d2e2b22235e585180522eae6a25dd100f326e682a3d68e0967ea9bfc258ab39fa53376322c24457b68093718a9ff93a0e26fdc5
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ main ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ main ]
|
20
|
+
schedule:
|
21
|
+
- cron: '21 7 * * 4'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v3
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v2
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v2
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v2
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Tests
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
types:
|
16
|
+
- opened
|
17
|
+
- synchronize
|
18
|
+
- reopened
|
19
|
+
- ready_for_review
|
20
|
+
- labeled
|
21
|
+
- unlabeled
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
changelog:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v4
|
28
|
+
- id: read-version
|
29
|
+
run: |
|
30
|
+
echo "::set-output name=VERSION::`cat lib/aoc_rb/version.rb | grep -i version | awk '{ print $3 }' | sed -e 's/\"//g'`"
|
31
|
+
- uses: dangoslen/changelog-enforcer@v2.3.1
|
32
|
+
with:
|
33
|
+
skipLabels: 'skip-changelog'
|
34
|
+
expectedLatestVersion: ${{ steps.read-version.outputs.VERSION }}
|
35
|
+
test:
|
36
|
+
runs-on: ubuntu-latest
|
37
|
+
strategy:
|
38
|
+
matrix:
|
39
|
+
ruby-version: ['3.1', '3.2', '3.3']
|
40
|
+
steps:
|
41
|
+
- uses: actions/checkout@v4
|
42
|
+
- name: Set up Ruby
|
43
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
44
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
45
|
+
# uses: ruby/setup-ruby@v1
|
46
|
+
uses: ruby/setup-ruby@v1
|
47
|
+
with:
|
48
|
+
ruby-version: ${{ matrix.ruby-version }}
|
49
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
50
|
+
- name: Run tests
|
51
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
/Gemfile.lock
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
/.idea/
|
14
|
+
|
15
|
+
# environment files
|
16
|
+
.ruby-gemset
|
17
|
+
.ruby-version
|
18
|
+
|
19
|
+
# gem build files
|
20
|
+
*.gem
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
- No unreleased changes!
|
9
|
+
|
10
|
+
## [0.0.1]
|
11
|
+
Initial release.
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- Created `AocInput` class with initial helper methods
|
15
|
+
|
16
|
+
[Unreleased]: https://github.com/pacso/aoc_rb_helpers/compare/v0.0.1...HEAD
|
17
|
+
[0.0.1]: https://github.com/pacso/aoc_rb_helpers
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Jon Pascoe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# AocRbHelpers
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/aoc_rb_helpers)
|
4
|
+
|
5
|
+
This gem provides helper classes and functions to simplify solving [Advent of Code](https://adventofcode.com) puzzles.
|
6
|
+
It is a companion gem to the [aoc_rb](https://github.com/pacso/aoc_rb) gem.
|
7
|
+
|
8
|
+
Be warned - using this gem might suck the fun out of solving the puzzles yourself!
|
9
|
+
|
10
|
+
## Getting Started
|
11
|
+
|
12
|
+
First of all, install the [aoc_rb](https://github.com/pacso/aoc_rb) gem and set up your project.
|
13
|
+
|
14
|
+
Next, add this gem to your project Gemfile, and run `bundle install`.
|
15
|
+
|
16
|
+
Open up `challenges/shared/solution.rb` in your project and require this gem at the top:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# frozen_string_literal: true
|
20
|
+
|
21
|
+
require "aoc_rb_helpers" # <-- Add this line
|
22
|
+
|
23
|
+
class Solution
|
24
|
+
...
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
You're good to go!
|
29
|
+
|
30
|
+
This gem additionally installs the excellent [puts_debuggerer](https://github.com/AndyObtiva/puts_debuggerer) gem, which you can use like this:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
pd some_object
|
34
|
+
```
|
35
|
+
|
36
|
+
You can read more on how you can use `pd` in their [README](https://github.com/AndyObtiva/puts_debuggerer/blob/master/README.md).
|
37
|
+
|
38
|
+
## Examples
|
39
|
+
|
40
|
+
Below are some examples of how you can use the features of this gem.
|
41
|
+
|
42
|
+
### Input manipulation
|
43
|
+
|
44
|
+
This example solution for 2024 Day 1 shows how the convenience methdos can be used to format the puzzle input:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# frozen_string_literal: true
|
48
|
+
|
49
|
+
module Year2024
|
50
|
+
class Day01 < Solution
|
51
|
+
def part_1
|
52
|
+
list_1, list_2 = data
|
53
|
+
list_1.each_with_index.sum { |item, index| (item - list_2[index]).abs }
|
54
|
+
end
|
55
|
+
|
56
|
+
def part_2
|
57
|
+
list_1, list_2 = data
|
58
|
+
list_1.each.sum { |item| item * list_2.count(item) }
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def data
|
64
|
+
aoc_input
|
65
|
+
.multiple_lines
|
66
|
+
.columns_of_numbers
|
67
|
+
.transpose
|
68
|
+
.sort_arrays
|
69
|
+
.data
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "lib/aoc_rb_helpers/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "aoc_rb_helpers"
|
5
|
+
spec.version = AocRbHelpers::VERSION
|
6
|
+
spec.authors = ["Jon Pascoe"]
|
7
|
+
spec.email = ["jon.pascoe@me.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Helper methods to simplify solving Advent of Code puzzles}
|
10
|
+
spec.description = %q{Enhances the aoc_rb gem with tools for parsing puzzle input, and handling various data manipulations within Advent of Code puzzle solutions.}
|
11
|
+
spec.homepage = "https://github.com/pacso/aoc_rb_helpers"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new("~> 3.1", ">= 3.1.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/pacso/aoc_rb_helpers"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/pacso/aoc_rb_helpers/blob/main/CHANGELOG"
|
18
|
+
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "aoc_rb", "~> 0.2", ">= 0.2.6"
|
27
|
+
spec.add_dependency "puts_debuggerer"
|
28
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AocInput
|
4
|
+
def initialize(input)
|
5
|
+
@raw_input = input
|
6
|
+
configure_method_access
|
7
|
+
end
|
8
|
+
|
9
|
+
def data
|
10
|
+
@data ||= @raw_input
|
11
|
+
end
|
12
|
+
|
13
|
+
def multiple_lines
|
14
|
+
@data = data.lines(chomp: true)
|
15
|
+
allow(:columns_of_numbers)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def columns_of_numbers(divider = nil)
|
20
|
+
can_call?(:columns_of_numbers, "call .multiple_lines first")
|
21
|
+
@data = data.map { |line| line.split(divider).map(&:to_i) }
|
22
|
+
allow(:sort_arrays)
|
23
|
+
allow(:transpose)
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def transpose
|
28
|
+
can_call?(:transpose, "call .columns_of_numbers first")
|
29
|
+
@data = data.transpose
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def sort_arrays
|
34
|
+
can_call?(:sort_arrays, "call .columns_of_numbers first")
|
35
|
+
@data = data.map { |ary| ary.sort }
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def configure_method_access
|
41
|
+
@can_call = {
|
42
|
+
columns_of_numbers: false,
|
43
|
+
sort_arrays: false,
|
44
|
+
transpose: false
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def allow(method_name)
|
49
|
+
@can_call[method_name.to_sym] = true
|
50
|
+
end
|
51
|
+
|
52
|
+
def can_call?(method_name, msg = "operation not permitted")
|
53
|
+
raise RuntimeError, msg unless @can_call[method_name.to_sym]
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aoc_rb_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Pascoe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aoc_rb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.2.6
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.2.6
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: puts_debuggerer
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Enhances the aoc_rb gem with tools for parsing puzzle input, and handling
|
48
|
+
various data manipulations within Advent of Code puzzle solutions.
|
49
|
+
email:
|
50
|
+
- jon.pascoe@me.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- ".github/workflows/codeql-analysis.yml"
|
56
|
+
- ".github/workflows/tests.yml"
|
57
|
+
- ".gitignore"
|
58
|
+
- CHANGELOG.md
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- aoc_rb_helpers.gemspec
|
64
|
+
- lib/aoc_rb_helpers.rb
|
65
|
+
- lib/aoc_rb_helpers/aoc_input.rb
|
66
|
+
- lib/aoc_rb_helpers/solution/input_handling.rb
|
67
|
+
- lib/aoc_rb_helpers/version.rb
|
68
|
+
homepage: https://github.com/pacso/aoc_rb_helpers
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://github.com/pacso/aoc_rb_helpers
|
73
|
+
source_code_uri: https://github.com/pacso/aoc_rb_helpers
|
74
|
+
changelog_uri: https://github.com/pacso/aoc_rb_helpers/blob/main/CHANGELOG
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.1'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 3.1.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.5.22
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Helper methods to simplify solving Advent of Code puzzles
|
97
|
+
test_files: []
|