Last active
May 5, 2018 20:38
-
-
Save fj/9aff06008a0fe5ce1f54fa34f363a648 to your computer and use it in GitHub Desktop.
a pairing interview for Recurse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "./printer" | |
class BinaryPrinter < Printer | |
def render | |
raise NotImplementedError | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
ruby "2.5.0" | |
gem "paint" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Printer | |
attr_reader :text | |
def initialize(text) | |
@text = text | |
end | |
def draw | |
puts render | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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