Skip to content

Instantly share code, notes, and snippets.

View seanhandley's full-sized avatar
🧀
Eating cheese

Sean Handley seanhandley

🧀
Eating cheese
View GitHub Profile
@seanhandley
seanhandley / see_buildings_left.rb
Last active November 13, 2024 05:26
See Buildings to the Left
# Given a list of integers representing the heights of buildings,
# return the maximum number of buildings that can be seen when
# looking from the left. A building can see another building if
# it is taller than all the buildings to its left. The height of
# the tallest building is included in the count.
def see_buildings_left(buildings)
return 0 if buildings.empty?
buildings.each_cons(2).inject(1) do |count, (a, b)|
count += 1 if a < b
MIN_LENGTH = 3
def max_product(collection)
raise "Minimum collection size is #{MAX_LENGTH}" if collection.length < MIN_LENGTH
collection.sort.last(MIN_LENGTH).reduce(:*)
end
max_product([2, 4, 1, 3, -5, 6])
# => 72
irb(main):001:1* def make_methods(&blk)
irb(main):002:1* (1..100).each { |i| define_method("number_#{i}".to_sym) { blk.call(i) } }
irb(main):003:0> end
=> :make_methods
irb(main):004:0>
irb(main):005:0> make_methods { |i| i }
=> 1..100
irb(main):006:0>
irb(main):007:0> puts number_2 # => 2
2
@seanhandley
seanhandley / 371vs372.diff
Created July 17, 2021 09:30
Diff of H3 lib function names from 3.7.1 to 3.7.2
10c10
< __faceIjkPentToGeoBoundary
---
> __faceIjkPentToCellBoundary
13a14
> __faceIjkToCellBoundary
15d15
< __faceIjkToGeoBoundary
25a26
> __gridDiskDistancesInternal
@seanhandley
seanhandley / a.rb
Last active November 17, 2020 21:09
Finding Raffle Numbers @ RubyConf2020
# Greedy Approach with Array#product
#
# $ time ruby a.rb
# Found it! Your raffle number is f8ryt
# real 2m12.019s
# user 2m7.764s
# sys 0m3.383s
require 'digest'
@seanhandley
seanhandley / plane_with_case.ex
Last active April 29, 2020 18:53
Elixir Pattern Matching
defmodule Plane do
defstruct is_fueled?: false, has_pilot?: false
def take_off(plane) do
case plane do
%Plane{ is_fueled?: false } ->
:needs_fuel
%Plane{ has_pilot?: false } ->
:needs_pilot
_ ->
@seanhandley
seanhandley / remote_team_meet.md
Last active March 15, 2020 08:59
Backend Team Final Interview Stage (Remote Edition)

🤝 Backend Team Final Interview Stage (Remote Edition)

During the next few weeks as we encourage all staff to work from home, we'll be trying out a new "final stage" of the hiring process.

Typically, we'd invite the candidate to the office to meet members of the engineering team in person, have lunch, and chat with the hiring manager.

The hard part (technical testing) is over and the focus is on getting to know each other. As such, our remote version of this process should focus on:

  • Social activities.
  • Letting the candidate see us working in-situ.
@seanhandley
seanhandley / about.md
Last active January 5, 2020 16:59
Intcode Quine
@seanhandley
seanhandley / robot.log
Created December 11, 2019 20:23
Debug log from the space hull painting robot @ Advent of Code 2019, Day 11
This file has been truncated, but you can view the full file.
[09340e50][0] RECEIVED 1
[09340e50][0] READ ARG 0 from position 8
[09340e50][0] INPUT 1
[09340e50][0] WRITE 1 to 8
[09340e50][2] READ ARG 0 from position 8
[09340e50][2] READ ARG 1 from absolute position 4
[09340e50][2] JNZ loc 8 is 1 (jumping to loc 350)
[09340e50][350] READ ARG 0 from absolute position 351
[09340e50][350] RB 672
[09340e50][352] READ ARG 0 from absolute position 353
@seanhandley
seanhandley / feedback_looped_amplifiers.txt
Created December 8, 2019 19:26
AoC 2019 Day 7, Part 2
This file has been truncated, but you can view the full file.
# Debug Mode On
[a] READ[1] => 8
[a] IN(8)
[a] WRITE[8] <= 5
[a] READ[8] => 5
[a] READ[4] => 10
[a] READ[5] => 8
[a] ADD(5, 10, 8)
[a] WRITE[8] <= 15
[a] READ[7] => 1