Skip to content

Instantly share code, notes, and snippets.

@kangkyu
kangkyu / gist:ea1d3606ea6e82c1fba0
Last active August 29, 2015 14:26
elm package install
elm package install
elm package install evancz/elm-html
<add & edit Bingo.elm>
# elm make --warn Bingo.elm --output index.html
elm reactor # and then open Bingo.elm file
module Bingo where
@kangkyu
kangkyu / transpose_mock.rb
Last active August 29, 2015 14:26
Thanks to Charlie, this is great for us to have 15-minute code kata every weekday .
# write a method called "transpose" that takes this array of arrays:
# [
# ['first', 'second'],
# ['third', 'fourth']
# ]
# and transposes it into this array of arrays
# [
# Take this array:
a = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
# and transform it into this array
# [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 0, 0]]
flat = a.flatten
# return the unique elements of this array:
# a = []
# 10000000.times{a.push(rand(100))}
# no array.uniq please
# extra credit -- in one function, count all the occurrences of each element of a
a = []
10000000.times{a.push(rand(100))}
def fizz(number)
number % 3 == 0 ? "fizz" : ""
end
def buzz(number)
number % 5 == 0 ? "buzz" : ""
end
def fizz_buzz(number)
(number.to_s + " " + fizz(number) + buzz(number))
# write a function called find_primes, where you pass in an integer (like 100),
# and your function will calculate all the prime numbers from 1 - 100
# https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
def find_primes(integer)
current_ary = (2..integer).to_a
current_idx = 0
while current_idx < current_ary.length
# Write a method leap_year?. It should accept a year value from the user, check whether it's a leap year, and then return true or false. Note: a century year, like 1900 and 2000, is a leap year only if it is divisible by 400.
def leap_year?(year)
year % 400 == 0 || year % 100 != 0 && year % 4 == 0
end
[1998, 1996, 2000, 2100].each do |year|
minutes = if leap_year?(year)
366 * 24 * 60
else
# Write a program that processes the string s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n" a line at a time, using all that we have learned so far.
s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n"
s.each_line.with_index 1 do |line, line_num|
puts "Line #{line_num}: #{line}"
end
def proper(phrase)
words = phrase.split(" ")
words.map {|word| cap_if_selected(word)}.join(" ")
end
def cap_if_selected(word)
word = word.each_char.map {|char| down_char(char)}.join
word[0] = up_char(word[0]) if selected(word)
word
end
# write a function called "x" that takes a string, and, if it has an odd number of characters, prints it out diagonally twice -- lower left to upper right, and upper left to lower right -- and those two strings share their middle character
def x(string)
if string.length.odd?
array = []
string.length.times do |row|
array << []
string.length.times do |col|
if col == row || col == (string.length - row - 1)
array[row][col] = string[col]