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
import Graphics.Element exposing (show) | |
import Array exposing (..) | |
import String exposing (..) | |
magicNumber : Array Int | |
magicNumber = | |
let | |
isNumber number = | |
String.right 1 (toString(number)) == "6" && | |
(String.append "6" (String.dropRight 1 (toString(number)))) |
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
-- Week 4: From One End to the Other: Find the smallest possible (positive) | |
-- integer that ends in a six such that if that six is removed and placed in front | |
-- of the remaining digits of the number, the resulting number will be four times | |
-- as large as the original. | |
function swap_first_and_last(t, n) | |
table.insert(t, 1, n) | |
return tonumber(table.concat(t)) | |
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
# From One End to the Other: Find the smallest possible | |
# (positive) integer that ends in a six such that if that six is removed and | |
# placed in front of the remaining digits of the number, the resulting number | |
# will be four times as large as the original. | |
i = 6 | |
loop do | |
digits = i.to_s.split('') | |
if digits.last == '6' && digits.rotate(-1).join.to_i == (i * 4) | |
puts i |
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
# Week 2 - Vim Buffer: I open up a new Vim buffer and type all the | |
# numbers 1 to 10,000, separated by spaces. Then, my cat walks on the keyboard | |
# and somehow activates a substitution command that replaces all the '0’ digits | |
# (zeros) with spaces. If I now sum up all the numbers in the buffer, as | |
# delineated by spaces, what is the total? | |
def vim_buffer(start = 1, limit) | |
(start..limit).flat_map { |num| num.to_s.gsub('0', ' ').split }.map(&:to_i).reduce(:+) | |
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
--[[ | |
Round Robin | |
Given 3 Teams (A, B, C), we want to organize a tournament schedule such that every team plays every other team exactly once. Here is a valid schedule for these 3 teams: | |
A - B | |
B - C | |
A - C | |
How about if we have N teams? Devise a general purpose algorithm that generates tournament schedules for N teams. | |
--]] |
NewerOlder