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 'benchmark' | |
class BagsContent | |
def initialize(name, count:) | |
self.name = name | |
self.count = Integer(count) | |
end | |
def to_s | |
name |
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 'benchmark' | |
class GroupAnswers | |
def self.from_lines(lines) | |
GroupAnswers.new(lines.map(&:chomp)) | |
end | |
def initialize(people) | |
questions = people.join('').chars.uniq | |
self.count = questions.count { |q| people.all? { |l| l.include?(q) } } |
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 'benchmark' | |
class BoardingPass | |
def self.from_binary(binary_position) | |
rows = binary_position[0...7].tr("FB", "01") | |
columns = binary_position[7..].tr("LR", "01") | |
BoardingPass.new((rows + columns).to_i(2)) | |
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 'benchmark' | |
class Passport | |
RULES = { | |
byr: -> (value) { /^[0-9]{4}$/.match?(value) && (1920..2002).cover?(value.to_i) }, | |
iyr: -> (value) { /^[0-9]{4}$/.match?(value) && (2010..2020).cover?(value.to_i) }, | |
eyr: -> (value) { /^[0-9]{4}$/.match?(value) && (2020..2030).cover?(value.to_i) }, | |
hgt: -> (value) { | |
match = /(^[1-9][0-9]+)(cm|in)$/.match(value) |
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 'benchmark' | |
class TreeGrid | |
def self.from(file) | |
rows = File.readlines(file) | |
TreeGrid.new(rows) | |
end | |
def initialize(rows) | |
self.rows = rows |
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 'benchmark' | |
class PasswordPolicy | |
def self.from_line(line) | |
length, char, password = line.split(' ') | |
first, second = length.split('-').map(&:to_i) | |
char = char.delete(':') | |
PasswordPolicy.new(positions: [first - 1, second - 1], char: char, password: password) | |
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
expenses = File.readlines('input.txt').map(&:to_i) | |
def find_matching_entries(entries, summation = 2020) | |
entries = entries.dup | |
while entries.size > 0 | |
current = entries.shift | |
match = entries.find do |compare| | |
current + compare == summation |
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
import { useState, useEffect } from 'react' | |
type FilePreview = string | null | |
export function useFilePreview( | |
nextFile: File | undefined, | |
defaultPreview: FilePreview = null | |
): FilePreview { | |
const [preview, setPreview] = useState<FilePreview>(null) |
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
import React, { useMemo } from "react"; | |
import { | |
createContext, | |
useContext, | |
useState, | |
useEffect, | |
useCallback | |
} from "react"; | |
import { | |
Appearance, |
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
import { Dimensions, ScaledSize, InteractionManager } from "react-native"; | |
import { useEffect, useState } from "react"; | |
type EventValue = { | |
window: ScaledSize; | |
screen: ScaledSize; | |
}; | |
/** | |
* Listens to dimension changes of "dim" and reports during an animation frame. |