advent_of_code_cli 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +101 -16
- data/lib/advent_of_code_cli/commands/download.rb +4 -1
- data/lib/advent_of_code_cli/commands/scaffold.rb +9 -9
- data/lib/advent_of_code_cli/commands/solve.rb +2 -4
- data/lib/advent_of_code_cli/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b2cac14f5226dc5a7c96642991455c2f33c794d2897669393c095ca350cdae2
|
4
|
+
data.tar.gz: e3d32b4654fc79cfb0fb86e2a33004019142ba6fb523215e2da7692b071879c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e1723a650da1f128a8f3cae5af52ae0f2e7b04845a883a82181f076d47b14b984a26b3ad6cc79ea4c1ce2272b6232531d2892e8790cd202dbcd053d1ccab98f
|
7
|
+
data.tar.gz: 71fc3eed81a924700eddb86a9c1f06c2a3ce0c43cbaf09e64f34c6078e3876f6d5409bbfbb4e37952165db444c866e3ebbbd5daaf63a79b7a725402570705f92
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
3
4
|
|
4
5
|
Style/Documentation:
|
5
6
|
Enabled: false
|
@@ -14,3 +15,9 @@ Style/StringLiteralsInInterpolation:
|
|
14
15
|
|
15
16
|
Layout/LineLength:
|
16
17
|
Max: 120
|
18
|
+
|
19
|
+
Metrics/AbcSize:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,33 +1,118 @@
|
|
1
|
-
#
|
1
|
+
# 🎄 Advent of Code CLI
|
2
2
|
|
3
|
-
|
3
|
+
> ⚠️ **Note:** This tool is under active development. I built in in a couple hours with no automated tests. Things may change between versions!
|
4
4
|
|
5
|
-
|
5
|
+
A little CLI tool that scaffolds and runs [Advent of Code](https://adventofcode.com) solutions in Ruby.
|
6
6
|
|
7
|
-
|
7
|
+
This project is heavily based on [advent-of-code-rust](https://github.com/arturopala/advent-of-code-rust). Go check it out!
|
8
8
|
|
9
|
-
|
9
|
+
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
Add this line to your application's `Gemfile`:
|
12
12
|
|
13
|
-
|
13
|
+
```ruby
|
14
|
+
gem "advent_of_code_cli"
|
15
|
+
```
|
14
16
|
|
15
|
-
|
17
|
+
Run `bundle install`.
|
16
18
|
|
17
19
|
## Usage
|
18
20
|
|
19
|
-
|
21
|
+
### Scaffold
|
20
22
|
|
21
|
-
|
23
|
+
This command will set up the files for any day of Advent of Code. It takes a nubmer between 1 and 25 as an argument.
|
22
24
|
|
23
|
-
|
25
|
+
```bash
|
26
|
+
bundle exec aoc_cli scaffold 1
|
27
|
+
```
|
24
28
|
|
25
|
-
|
29
|
+
This will result in the following output:
|
26
30
|
|
27
|
-
|
31
|
+
```
|
32
|
+
Creating file: 01.rb...
|
33
|
+
Creating inputs directory...
|
34
|
+
Creating file: inputs/01.txt...
|
35
|
+
Creating examples directory...
|
36
|
+
Creating examples/01 directory...
|
37
|
+
```
|
38
|
+
|
39
|
+
The file `01.rb` will have the following structure:
|
40
|
+
|
41
|
+
```rb
|
42
|
+
module Day01
|
43
|
+
class << self
|
44
|
+
def part_one(input)
|
45
|
+
raise NotImplementedError
|
46
|
+
end
|
47
|
+
|
48
|
+
def part_two(input)
|
49
|
+
raise NotImplementedError
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
...where `input` is an `Array[String]` of all the lines without newlines.
|
56
|
+
|
57
|
+
I would love to make this structure configurable in the future.
|
58
|
+
|
59
|
+
### Download
|
60
|
+
|
61
|
+
This command will download the input for a given day.
|
62
|
+
|
63
|
+
In order for this to work, you must provide your Advent of Code session cookie to the program in an environment variable:
|
64
|
+
|
65
|
+
```bash
|
66
|
+
export AOC_COOKIE=your-cookie
|
67
|
+
```
|
68
|
+
|
69
|
+
Once the environment variable is set, you can request your personal input for any day.
|
70
|
+
|
71
|
+
```bash
|
72
|
+
bundle exec aoc_cli download 1
|
73
|
+
```
|
28
74
|
|
29
|
-
|
75
|
+
This will create the following output:
|
30
76
|
|
31
|
-
|
77
|
+
```
|
78
|
+
Fetching input...
|
79
|
+
Writing input to inputs/01.txt...
|
80
|
+
Done!
|
81
|
+
```
|
82
|
+
|
83
|
+
By default, the CLI will request the input for this year, but you can request previous years' input by passing a `--year` flag.
|
84
|
+
|
85
|
+
```bash
|
86
|
+
bundle exec aoc_cli download 1 --year 2021
|
87
|
+
```
|
88
|
+
|
89
|
+
### Solve
|
90
|
+
|
91
|
+
This command will run your solution to a certain day's puzzle.
|
92
|
+
|
93
|
+
```
|
94
|
+
bundle exec aoc_cli solve 1
|
95
|
+
```
|
96
|
+
|
97
|
+
This will create the following output:
|
98
|
+
|
99
|
+
```
|
100
|
+
Reading input...
|
101
|
+
Loading solution...
|
102
|
+
|
103
|
+
Running part one...
|
104
|
+
Part one result: 10000
|
105
|
+
Took 0.000259 seconds to solve
|
106
|
+
|
107
|
+
Running part two...
|
108
|
+
Part two result: 10000
|
109
|
+
Took 0.00026 seconds to solve
|
110
|
+
|
111
|
+
Done!
|
112
|
+
```
|
113
|
+
|
114
|
+
This command expects files to be in the format provided by the `scaffold` command. Once again, I would love to make this configurable but haven't gotten around to it yet.
|
115
|
+
|
116
|
+
## Contributing
|
32
117
|
|
33
|
-
|
118
|
+
Issues and code contributions are welcome! Happy Advent of Code to all who celebrate! 🎁
|
@@ -31,7 +31,7 @@ module AdventOfCode
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def cookie
|
34
|
-
@cookie ||= ENV
|
34
|
+
@cookie ||= ENV.fetch("AOC_COOKIE", nil)
|
35
35
|
end
|
36
36
|
|
37
37
|
def cookie_present?
|
@@ -46,6 +46,9 @@ module AdventOfCode
|
|
46
46
|
|
47
47
|
request = Net::HTTP::Get.new(url)
|
48
48
|
request["Cookie"] = "session=#{cookie}"
|
49
|
+
# The creator of Advent of Code has requested that automated tools send identifying information
|
50
|
+
# when making requests: https://www.reddit.com/r/adventofcode/comments/z9dhtd
|
51
|
+
request["User-Agent"] = "github.com/egiurleo/advent_of_code_cli by emily.samp@icloud.com"
|
49
52
|
|
50
53
|
response = https.request(request)
|
51
54
|
response.read_body
|
@@ -32,17 +32,17 @@ module AdventOfCode
|
|
32
32
|
|
33
33
|
def solution_file_contents
|
34
34
|
<<~RUBY
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
module Day#{day_string}
|
36
|
+
class << self
|
37
|
+
def part_one(input)
|
38
|
+
raise NotImplementedError
|
39
|
+
end
|
40
|
+
|
41
|
+
def part_two(input)
|
42
|
+
raise NotImplementedError
|
43
|
+
end
|
43
44
|
end
|
44
45
|
end
|
45
|
-
end
|
46
46
|
RUBY
|
47
47
|
end
|
48
48
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'benchmark'
|
4
|
-
|
5
3
|
module AdventOfCode
|
6
4
|
module Commands
|
7
5
|
class Solve < Command
|
@@ -10,7 +8,7 @@ module AdventOfCode
|
|
10
8
|
raise MissingSolutionError unless File.exist?(solution_file_name)
|
11
9
|
|
12
10
|
say "Reading input..."
|
13
|
-
input = File.
|
11
|
+
input = File.readlines(input_file_name, chomp: true)
|
14
12
|
|
15
13
|
say "Loading solution..."
|
16
14
|
load(solution_file_name)
|
@@ -34,7 +32,7 @@ module AdventOfCode
|
|
34
32
|
end_time = Time.now
|
35
33
|
|
36
34
|
say "Part #{part} result: #{result}"
|
37
|
-
say "Took #{end_time-start_time} seconds to solve"
|
35
|
+
say "Took #{end_time - start_time} seconds to solve"
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: advent_of_code_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emily Samp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -54,6 +54,7 @@ licenses:
|
|
54
54
|
metadata:
|
55
55
|
homepage_uri: https://github.com/egiurleo/advent_of_code_cli
|
56
56
|
source_code_uri: https://github.com/egiurleo/advent_of_code_cli
|
57
|
+
rubygems_mfa_required: 'true'
|
57
58
|
post_install_message:
|
58
59
|
rdoc_options: []
|
59
60
|
require_paths:
|
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
requirements: []
|
72
|
-
rubygems_version: 3.3.
|
73
|
+
rubygems_version: 3.3.26
|
73
74
|
signing_key:
|
74
75
|
specification_version: 4
|
75
76
|
summary: A CLI tool to scaffold and run Advent of Code solutions.
|