This file contains 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 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 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 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 valid_triangle?(a, b, c) | |
(a + b > c) && (a + c > b) && (b + c > a) | |
end |
This file contains 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 times_table(rows) | |
bigarray = [] | |
1.upto(rows) do |x| | |
newarrayrow=[] | |
1.upto(rows) do |y| | |
newarrayrow << x*y | |
end | |
bigarray << newarrayrow.join(' ') | |
end | |
This file contains 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 numwords any_number | |
bignumwords any_number, [] | |
end | |
def bignumwords number, big_array | |
place_names = {1 => 'thousand', | |
2 => 'million', | |
3 => 'billion', | |
4 => 'trillion'} | |
comma_count = Math.log(number,10).floor / 3 |
This file contains 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 digitsum num | |
currentsum = 0 | |
(Math.log(num,10).ceil).downto(0) do |digit| | |
currentsum = currentsum + num/(10**digit) | |
num = num%(10**digit) | |
end | |
currentsum | |
end |
This file contains 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 countofmultiples (num,firstfactor,secondfactor) | |
count = 0 | |
1.upto(num-1) do |check| | |
if check % firstfactor == 0 || check % secondfactor == 0 | |
count += check | |
end | |
end | |
count | |
end |
This file contains 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 sumofprimesbelow number | |
prime_array = [3,5] | |
current_num = 7 | |
while current_num < number | |
prime_array.each do |factor| | |
if current_num % factor == 0 | |
break | |
elsif factor > Math.sqrt(current_num) | |
prime_array << current_num | |
break |
This file contains 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 |
OlderNewer