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 range(start_num,end_num) | |
return [end_num] if start_num == end_num | |
nums = [] | |
if start_num > end_num | |
nums += [start_num] + range(start_num-1,end_num) | |
else | |
nums += [start_num] + range(start_num+1,end_num) | |
end | |
nums | |
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 prime(num) | |
return [] if num < 2 | |
primes = [] | |
2.upto(num) { |x| primes[x] = x} | |
2.upto(Math.sqrt(num)) { |x| primes[x] ? (x*x).step(num,x) { |x2| primes[x2] = nil } : next} | |
primes.compact | |
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 quick_sort(nums) | |
return nums if nums.length == 1 | |
mid = nums.length / 2 | |
left = [] | |
right = [] | |
0.upto(nums.length-1) do |i| | |
if nums[i] <= nums[mid] | |
left << nums[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
def powers_rec(num,power) | |
return num if power == 1 | |
total = num * powers_rec(num,power-1) | |
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 josephus(count, skip) | |
#catch errors | |
return 0 if count == 1 | |
#base case | |
return count-1 if skip == 1 | |
#generally calls base case | |
if skip>count | |
return (josephus(count-1,skip)+skip) % count |
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
# c2 c4 | |
# h7 h5 | |
# h2 h4 | |
# a7 a5 | |
# d1 a4 | |
# a8 a6 | |
# a4 a5 | |
# a6 h6 | |
# a5 c7 |
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
SELECT DISTINCT a.yr | |
FROM nobel a | |
LEFT OUTER JOIN nobel b | |
ON a.yr=b.yr | |
AND b.subject NOT IN ('Economics','Literature','Medicine','Peace','Physics') | |
WHERE b.subject IS NULL | |
AND a.subject = 'Physics' |
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
.headers on | |
.mode column |
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
function bind(func, object) { | |
return function () { | |
return func.apply(object, arguments); | |
}; | |
} | |
Function.prototype.myBind = function (context) { | |
var that = this; | |
return function () { | |
return that.apply(context, arguments); |
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
https://github.com/addyosmani/backbone-fundamentals |
OlderNewer