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
convertCoin(10.25); | |
convertCoin(22.99); | |
convertCoin(159.79); | |
convertCoin(3159.69); | |
function convertCoin(input) { | |
var result = [{ | |
'name': 'dollar', | |
'amount': 0, |
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 shuffle(l) | |
return l[0] if l.size == 1 | |
i = l.index(l.sample) | |
h = l[i] | |
l.delete_at(i) | |
return [h, shuffle(l)].flatten | |
end | |
array = [1,2,3,4,5,6] | |
p shuffle(array) |
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
#WORK IN PROGRESS : fill water | |
require 'pp' | |
def shuffle(l) | |
return l[0] if l.size == 1 | |
i = l.index(l.sample) | |
h = l[i] | |
l.delete_at(i) | |
return [h, shuffle(l)].flatten |
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
var fact = function (n) { | |
return (n == 1) ? 1 : n * fact(n-1); | |
} | |
console.log( fact(7)); | |
console.log( fact(10) == 10*9*8*7*6*5*4*3*2*1); |
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
require 'pp' | |
def recursive(n) | |
n == 1 ? 1 : n*recursive(n-1) | |
end | |
pp recursive(7) |
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
require 'pp' | |
def recursive(n) | |
n == 1 ? 1 : n*recursive(n-1) | |
end | |
pp recursive(7) |
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
require 'pp' | |
def search(a, t) | |
#pp "a:#{a} t:#{t}" | |
return a[0] if a.size == 1 | |
middle_index = (a.size/2).to_i | |
#pp "m:#{middle_index} a[m]:#{a[middle_index]}" | |
t < a[middle_index] ? search(a[0..middle_index-1],t) : search(a[middle_index..a.size], 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
class Linkedlist(object): | |
def __init__(self, value): | |
self.value = value | |
self.prev_node = None | |
self.nxt_node = None | |
print 'initialized node', self | |
def insert_last(self, last_node): | |
if last_node: | |
last_node.nxt_node = self |
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
require 'pp' | |
def dual (a) | |
return [] if !a.any? | |
return [a[0]] if a.size == 1 | |
head = [a[1], a[0]] | |
tail = a[2..a.size] | |
(head << dual(tail)).compact.flatten | |
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
require 'pp' | |
class LinkedList | |
attr_accessor :head | |
def initialize(head=nil) | |
@head = head | |
head | |
end |
OlderNewer