Skip to content

Commit ce92925

Browse files
committed
Prep for solving
1 parent 6ada668 commit ce92925

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.session
12
*.gem
23
*.rbc
34
/.config

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
# adventofcode2016
1+
# Advent of Code 2015 #
2+
23
Solutions for the 2016 edition of the Advent of Code - http://adventofcode.com/2016
4+
5+
Back again for another year, the little [Advent of Code] site that has a new pair of problems to solve each new day (i.e., midnight Eastern time) and this repository holds my solutions using [ruby](http://ruby-lang.org)
6+
7+
My solutions for the original 2015 installment of the Advent of Code is in the repo: [rab/adventofcode2015](https://github.com/rab/adventofcode2015)
8+
9+
When I was recognized on the [Leaderboard]
10+
11+
Day | Position
12+
--- | --------
13+
14+
[Advent of Code]: http://www.adventofcode.com/2016/
15+
[Leaderboard]: http://www.adventofcode.com/leaderboard
16+
[Stats]: http://www.adventofcode.com/stats
17+
[Github]: http://github.com/

day_template.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require_relative 'input'
2+
3+
day = __FILE__[/\d+/].to_i(10)
4+
input = Input.for_day(day)
5+
6+
puts "solving day #{day} from input\n#{input.inspect}"

input.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'uri'
2+
require 'net/http'
3+
4+
module Input
5+
extend self
6+
def for_day(day)
7+
cache_file = 'day%02d_input.txt'%[day]
8+
if File.exist? cache_file
9+
File.read(cache_file)
10+
else
11+
uri = URI('http://adventofcode.com/2016/day/%s/input'%[day.to_s])
12+
req = Net::HTTP::Get.new(uri)
13+
req['Cookie'] = File.read('./.session') if File.exist?('./.session')
14+
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
15+
http.request(req)
16+
}
17+
res.body.tap {|contents| File.write(cache_file, contents) }
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)