-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oasis.rb
57 lines (50 loc) · 1.28 KB
/
oasis.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
module AdventOfCode
module Puzzles2023
module Day09
##
# Class for managing the OASIS reports.
class OASIS
##
# Class for representing a feature.
# A feature is a set of values, than can have a predicted value.
class Feature
##
# Array of values
# @return [Array<Integer>]
attr_reader :values
##
# Predicted value. May be nil.
# @param [Integer]
# @return [Integer]
attr_accessor :predicted_value
##
# @param [Array<Integer>] values
def initialize(values:)
@values = values
end
end
##
# Array of features.
# @return [Array<Feature>] features
attr_reader :report
##
# @param [String] file path
def initialize(file:)
parse_file(file)
end
protected
##
# Parse the file's contents.
#
# @param [String] file path
def parse_file(file)
file_contents = File.readlines(file, chomp: true)
@report = file_contents.map do |line|
Feature.new(values: line.split.map(&:to_i))
end
end
end
end
end
end