Skip to content

Instantly share code, notes, and snippets.

View shtakai's full-sized avatar
🐤
I am leaning Ada.

Alyson shtakai

🐤
I am leaning Ada.
View GitHub Profile
convertCoin(10.25);
convertCoin(22.99);
convertCoin(159.79);
convertCoin(3159.69);
function convertCoin(input) {
var result = [{
'name': 'dollar',
'amount': 0,
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)
#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
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);
require 'pp'
def recursive(n)
n == 1 ? 1 : n*recursive(n-1)
end
pp recursive(7)
require 'pp'
def recursive(n)
n == 1 ? 1 : n*recursive(n-1)
end
pp recursive(7)
@shtakai
shtakai / binsearch.rb
Created May 10, 2016 19:00
binary search 2016/05/10
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
@shtakai
shtakai / linkedlist.py
Created May 11, 2016 05:56
linkedlist
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
@shtakai
shtakai / dual.rb
Created May 13, 2016 01:11
ex [1,2,3,4] -> [2,1,4,3]
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
@shtakai
shtakai / linkedlist.rb
Created May 16, 2016 21:29
linked list(dirty)
require 'pp'
class LinkedList
attr_accessor :head
def initialize(head=nil)
@head = head
head
end