Skip to content

Instantly share code, notes, and snippets.

@gglin
gglin / collatz.rb
Created August 22, 2013 00:20
Project Euler Problem 14 - Collatz Sequence
# The following iterative sequence is defined for the set of positive integers:
# n ->n/2 (n is even) n ->3n + 1 (n is odd)
# Using the rule above and starting with 13, we generate the following sequence:
# 13 40 20 10 5 16 8 4 2 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
# Which starting number, under one million, produces the longest chain?
@gglin
gglin / .pryrc.rb
Last active December 19, 2015 08:59
My .pryrc file
class Object
# all methods named 'local_(*)_methods'
# should return '(*)_methods' minus those that exist in Object
def method_missing(method_name, klass = Object, *args, &block)
if method_name.to_s[0..5] == "local_" && method_name.to_s[-7..-1] == "methods" && !method_name.to_s[6..-1].include?("local")
subname = method_name.to_s[6..-1]
self.send(subname, *args, &block) - klass.send(subname, *args, &block)
else
super(method_name, *args, &block)
@gglin
gglin / calc.js
Created July 2, 2013 22:26
jQuery Calculator
/* Write the JS necessary to calculate values after a number is changed inside the form field.
Hints:
1.) Learn about change event methods: http://api.jquery.com/change/
2.) Learn about retrieving values from form inputs: http://api.jquery.com/val/
3.) Learn how to select specific inputs using eq selectors: http://api.jquery.com/eq-selector/
*/
$(document).ready(function() {
@gglin
gglin / palindromes.rb
Last active December 19, 2015 06:09
Day 22 Warmup
class Palindromes
def initialize(hash = {})
hash[:max_factor] ||= 2
hash[:min_factor] ||= 1
@max_factor = hash[:max_factor]
@min_factor = hash[:min_factor]
@palins = []
end
@gglin
gglin / Alien_PB&J
Last active December 18, 2015 01:19
Create a numbered list that contains instructions for making a peanut butter and jelly sandwich for a tourist alien.
Questions:
-what is the criteria for a "successful" PB&J Sandwich?
-what are other variables we want to account for? e.g.:
-minimize contamination of PB into Jelly jar and vice versa
-make containers easy to reuse
-assuming hands and plate are cleaner than table, prevent bread from touching table
-can we infer that the situation in the picture is also part of the consideration? i.e. the PB, Jelly, Bread are labeled, everything is within reach by the alien
-is the alien able to do actions with his hands that a normal human can (at least the ones involved in making a sandwich), especially opening a jar or the bread packaging
Assuming yes to all of the above: