Skip to content

Instantly share code, notes, and snippets.

View colintsteele's full-sized avatar

Colin Steele colintsteele

View GitHub Profile
@colintsteele
colintsteele / day6.rb
Last active December 6, 2021 17:25
lanternfish
# day 6
test_input = [3, 4, 3, 1, 2]
input = test_input # set puzzle input here
@lantern_fish = Hash.new(0)
0.upto(input.max) do |counts|
@lantern_fish[counts] = input.count(counts)
end
@colintsteele
colintsteele / d3.rb
Created December 3, 2021 17:20
bitmarine
test_input = %w[00100 11110 10110 10111 10101 01111 00111 11100 10000 11001 00010 01010]
# puzzle_input <<-BIN
# # your puzzle input pasted here
# BIN
def most_common(list)
count = list.tally
if count.values.uniq.size == 1 # equal number of 1s and 0s
'1'
@colintsteele
colintsteele / d2.rb
Created December 2, 2021 16:25
AoC#2
pinput = <<-PUZ
# your input goes here
PUZ
sub = Submarine.new(pinput.split("\n"))
sub.go_brr
sub.where
class Submarine
attr_reader :aim, :horizontal_pos, :vertical_pos, :movements
@colintsteele
colintsteele / gwf.rb
Last active April 16, 2018 16:37
great weapon fighting
def get_avg(die_type, dice_count = 1)
rolls = 1_000_000
avg = (1..rolls).inject(0.0) do |acc, _n|
dice_count.times do
roll = rand(die_type)
acc += ( (roll < 3) ? rand(die_type) : roll )
end
acc
end
@colintsteele
colintsteele / Trapezium.java
Created May 17, 2017 01:49
Completed assignment
public void draw(int indentation) { //while
boolean shrinks = (topWidth > bottomWidth);
if(shrinks){
for (int lineWidth = topWidth; lineWidth >= bottomWidth; lineWidth-= 2) {
int backgroundCharacterCount = (width - lineWidth)/2;
printLine(lineWidth, backgroundCharacterCount);
}
} else {
for (int lineWidth = topWidth; lineWidth <= bottomWidth; lineWidth+= 2) {
@colintsteele
colintsteele / text_stuff.js
Last active December 22, 2016 18:03
chrome extension for name processing and hyperlinking
//send to Alchemy
//send to Google Custom Search API
function
$.ajax({
//API key and search engine id are embedded in url
//Process returns URL of first image result equal to face
url: "https://www.googleapis.com/customsearch/v1?key=AIzaSyBh1mbRlS0Mutavt8PuoIytqpn0Bsn_JIM&cx=013039004155227536814:lobto-0zlua&",
data: {