Skip to content

Instantly share code, notes, and snippets.

View holdenhinkle's full-sized avatar

Holden Hinkle holdenhinkle

View GitHub Profile
@holdenhinkle
holdenhinkle / ocr.rb
Last active October 3, 2015 14:59
ocr_v2
require 'pry'
class OCR
attr_reader :text
def initialize(text)
@text = text
end
def convert
@holdenhinkle
holdenhinkle / triplet.rb
Last active March 12, 2016 16:25
pythagorean_triplet
require 'pry'
class Triplet
attr_reader :a, :b, :c
def initialize(a, b, c)
@a = a
@b = b
@c = c
end
@holdenhinkle
holdenhinkle / power_ball_picker.rb
Last active January 14, 2016 00:49
PowerBall Picker
require 'pry'
WHITE_BALLS = [*1..69]
POWERBALL = [*1..26]
NUM_WHITE_BALLS_NEEDED = 5
FIRST_WHITE_BALL = WHITE_BALLS.first
LAST_WHITE_BALL = WHITE_BALLS.last
FIRST_POWERBALL = POWERBALL.first
LAST_POWERBALL = POWERBALL.last
class CircularBuffer
attr_accessor :buffer, :read_index, :write_index
def initialize(length)
@buffer = Array.new(length)
@read_index = 0
@write_index = 0
end
def read
@holdenhinkle
holdenhinkle / grade_school.rb
Last active January 31, 2016 01:33
Grade School
class School
attr_accessor :grades
def initialize
@grades = {}
end
def to_h
grades.map { |grade, name| grades[grade] = name.sort }
grades.sort.to_h
@holdenhinkle
holdenhinkle / trinary.rb
Last active March 12, 2016 21:01
Trinary
class Trinary
attr_reader :number
def initialize(value)
@number = value
end
def to_decimal
return 0 if number.match(/[^0-2]/)
converted_num = 0
number.split('').reverse.each_with_index do |num, index|
converted_num += num.to_i * 3 ** index
@holdenhinkle
holdenhinkle / hex.rb
Last active March 13, 2016 04:02
Convert Hex to Decimal
class Hex
HEX = { '1' => 1, '2' => 2, '3' => 3,
'4' => 4, '5' => 5, '6' => 6,
'7' => 7, '8' => 8, '9' => 9,
'a' => 10, 'b' => 11, 'c' => 12,
'd' => 13, 'e' => 14, 'f' => 15 }
attr_reader :string
def initialize(input)
@holdenhinkle
holdenhinkle / topic_17.js
Last active August 13, 2019 21:03
LS Practice Problem: Class Records Summary
var studentScores = {
student1: {
id: 123456789,
scores: {
exams: [90, 95, 100, 80],
exercises: [20, 15, 10, 19, 15],
},
},
student2: {
id: 123456799,
@holdenhinkle
holdenhinkle / topic_12.js
Last active August 23, 2019 12:38
Code Review: Longest Sentence
function longestSentence(text) {
let biggestSentence = { sentence: null, wordCount: 0, };
while (text.length > 0) {
sentence = text.match(/^[\w\d\s,-]+\b([.!?]\s*)/i)[0];
text = text.replace(sentence, '');
sentence = sentence.trim();
let wordCount = sentence.split(' ').length;
if (biggestSentence.wordCount < wordCount) {
function railFenceCipher(operation, string, height = 3) {
function encrypt(string, height, fence) {
let currentRail = 0;
let moveUp = true;
let moveDown = false;
for (let i = 0; i < fence[0].length; i += 1) {
fence[currentRail].splice(i, 1, string[i]);
if ((moveUp && currentRail + 1 > height - 1) ||