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
// we're starting this function with an IIFE http://benalman.com/news/2010/11/immediately-invoked-function-expression/ | |
// it's important to start this with a semicolon because otherwise any previously loaded JavaScript might try and invoke | |
// its last line using the anonymous function that we define here as its argument, and then invoke the resulting return value | |
// on line 63. That would be silly, yo. So we explicitly end the previous thought with a semicolon. | |
;(function () { | |
// we define an array of all of the possible predictions that our eight ball can make. | |
// unlike in Ruby, the use of all caps is purely conventional; JavaScript has no opinions about | |
// what capitalized variables mean. | |
var PREDICTIONS = [ |
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
// we're starting this function with an IIFE http://benalman.com/news/2010/11/immediately-invoked-function-expression/ | |
// it's important to start this with a semicolon because otherwise any previously loaded JavaScript might try and invoke | |
// its last line using the anonymous function that we define here as its argument, and then invoke the resulting return value | |
// on line 63. That would be silly, yo. So we explicitly end the previous thought with a semicolon. | |
;(function () { | |
// CLOSURES | |
function captureWhatNumberIsRightNow (number) { | |
return function () { |
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
body { | |
background-image: url('http://pcmreviews.com/news/wp-content/uploads/2012/01/Red-carpet.jpg'); | |
background-size: cover; | |
background-repeat: no-repeat; | |
background-position: center; | |
color: white; | |
font-family: 'Parisienne', cursive; | |
} | |
.header{ |
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
def north_korean_cipher message, offset = 4 | |
unexaggerate message.chars.map{|char| decode char, offset}.join('') | |
end | |
def unexaggerate message | |
message.gsub(/\d+/) { |num| num.to_i / 100 } | |
end | |
def decode char, offset | |
case |
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
def hundred_pairs(array, target = 100) | |
array.sort! | |
results = [] | |
min, max = array.shift, array.pop | |
while min && max | |
while min + max > target | |
max = array.pop | |
end | |
while min && max && min + max < target | |
min = array.shift |
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
TIGERS = {1 => 'Morgan, Kiera, John', 2 => 'Dave, Bruno, Max', | |
3 => 'David, Nick, Lionel', 4 => 'Elmer, Juke, Robert', | |
5 => 'Tom, Tyler, Gary', 6 => 'Sunny, Daniel, Nathan', | |
7 => 'Doug, Rao, Nishant'} | |
class Console | |
def initialize | |
@gophers = {} | |
puts "Welcome to GroupMatcher(tm)!" | |
puts "When you've finished all groups, type 'Match!'" |
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
def roman_to_integer string | |
string.upcase! | |
raise ArgumentError if /[MDCLXVI]*/.match(string).to_s != string | |
letter_values = {'M' => 1000, | |
'D' => 500, | |
'C' => 100, | |
'L' => 50, | |
'X' => 10, | |
'V' => 5, | |
'I' => 1} |
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
whichtrinum = 1 | |
while true | |
trinum = (whichtrinum * (whichtrinum + 1)) / 2 | |
numtofactor = trinum | |
factors = [] | |
factor = 2 | |
while numtofactor != 1 | |
if numtofactor % factor == 0 | |
factors << factor | |
numtofactor = numtofactor / factor |
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
def is_fibonacci?(num) | |
phi = (1 + 5.0**0.5)/2 | |
which_fib = ((Math.log(num)+Math.log(5.0**0.5)) / Math.log(phi)).round | |
num == fibonacci(which_fib) | |
end | |
def fibonacci(n) | |
if n==0 | |
0 |
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
def largestproduct(nums_as_a_string) | |
currentmax = 0 | |
arry = nums_as_a_string.split("\n") | |
arry.map! { |row_as_a_string| row_as_a_string.split.map! { |digit| digit.to_i } } | |
0.upto( (arry.length - 1).to_i ) do |row| | |
0.upto( (arry[row].length - 1).to_i ) do |col| | |
if col <= (arry[row].length - 4) | |
rowprod = arry[row][col]*arry[row][col+1]*arry[row][col+2]*arry[row][col+3] | |
currentmax = [currentmax,rowprod].max | |
end |
NewerOlder