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 'pry' | |
| class OCR | |
| attr_reader :text | |
| def initialize(text) | |
| @text = text | |
| end | |
| def convert |
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 'pry' | |
| class Triplet | |
| attr_reader :a, :b, :c | |
| def initialize(a, b, c) | |
| @a = a | |
| @b = b | |
| @c = c | |
| 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 '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 |
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 CircularBuffer | |
| attr_accessor :buffer, :read_index, :write_index | |
| def initialize(length) | |
| @buffer = Array.new(length) | |
| @read_index = 0 | |
| @write_index = 0 | |
| end | |
| def read |
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 School | |
| attr_accessor :grades | |
| def initialize | |
| @grades = {} | |
| end | |
| def to_h | |
| grades.map { |grade, name| grades[grade] = name.sort } | |
| grades.sort.to_h |
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 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 |
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 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) |
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
| var studentScores = { | |
| student1: { | |
| id: 123456789, | |
| scores: { | |
| exams: [90, 95, 100, 80], | |
| exercises: [20, 15, 10, 19, 15], | |
| }, | |
| }, | |
| student2: { | |
| id: 123456799, |
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
| 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) { |
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
| 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) || |
OlderNewer