Skip to content

Instantly share code, notes, and snippets.

@fj
Last active May 5, 2018 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fj/9aff06008a0fe5ce1f54fa34f363a648 to your computer and use it in GitHub Desktop.
Save fj/9aff06008a0fe5ce1f54fa34f363a648 to your computer and use it in GitHub Desktop.
a pairing interview for Recurse
require_relative "./printer"
class BinaryPrinter < Printer
def render
raise NotImplementedError
end
end
#! /usr/bin/env ruby
require "paint"
require "datetime"
require_relative "./text_printer"
class Clock
attr_reader :time
def initialize(time_string)
@time = DateTime.parse(time_string)
end
def to_s
time.strftime("%H:%M:%S")
end
end
clock = Clock.new(Time.now)
TextPrinter.new(clock.to_s).draw
BinaryPrinter.new(clock.to_s).draw
source "https://rubygems.org"
ruby "2.5.0"
gem "paint"
class Printer
attr_reader :text
def initialize(text)
@text = text
end
def draw
puts render
end
end
require_relative './printer'
class TextPrinter < Printer
def render
raise NotImplementedError
end
def digits
@digits ||= {
"0": %w(
.xxx.
x...x
x...x
x...x
.xxx.
),
"1": %w(
xxx..
..x..
..x..
..x..
xxxxx
),
"2": %w(
.xxx.
x...x
..xx.
.x...
xxxxx
),
"3": %w(
xxxx.
....x
xxxx.
....x
xxxx.
),
"4": %w(
x..x.
x..x.
xxxxx
...x.
...x.
),
"5": %w(
xxxxx
x....
xxxx.
....x
xxxx.
),
"6": %w(
.xxx.
x....
xxxx.
x...x
.xxx.
),
"7": %w(
xxxxx
....x
...x.
..x..
.x...
),
"8": %w(
.xxx.
x...x
.xxx.
x...x
.xxx.
),
"9": %w(
.xxx.
x...x
.xxxx
....x
.xxx.
)
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment