This file contains hidden or 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 karatsuba(x, y) | |
return x * y if (x < 10) || (y < 10) | |
n = [x.to_s.size, y.to_s.size].max | |
n2 = n/2 | |
a, b = x.divmod(10**n2) | |
c, d = y.divmod(10**n2) | |
step_1 = karatsuba(a,c) | |
step_2 = karatsuba(b,d) |
This file contains hidden or 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 merge_sort(ary) | |
size = ary.size | |
return ary if size <= 1 | |
mid = size/2 | |
left, right = ary[0..mid-1], ary[mid..-1] | |
left, right = merge_sort(left), merge_sort(right) | |
merge(left, right) |
This file contains hidden or 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 | |
# | |
# $*.map{|a|(i=a=~/0/)?(v=*?1..?9).fill{|j|v-=[a[j+i-k=i%9],a[ | |
# k+j*=9],a[j%26+i-i%3-i%27+k]]}+v.map{|k|$*<<$`+k+$'}:p(a)} | |
# | |
# | |
# To | |
start = Time.now | |
counter = 1 |
This file contains hidden or 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 karatsuba x, y | |
return x * y if (x < 10) || (y < 10) | |
n = [x.to_s.size, y.to_s.size].max | |
n2 = n/2 | |
a, b = x.divmod(10**n2) | |
c, d = y.divmod(10**n2) | |
step_1 = karatsuba(a,c) | |
step_2 = karatsuba(b,d) |
This file contains hidden or 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 'date' | |
def random_date_between(args) | |
start, finish = args[:start], args[:finish] | |
start, finish = [start, finish].map do |datetime| | |
case | |
when datetime.is_a?(DateTime) then datetime.to_time.to_i | |
when datetime.is_a?(Date) then DateTime.parse(datetime.to_s).to_time.to_i | |
when datetime.is_a?(String) then DateTime.parse(datetime).to_time.to_i | |
else |
This file contains hidden or 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 SudokuSolver { | |
constructor(board) { | |
this.board = board; | |
} | |
solve() { | |
const index = this.board.indexOf('0'); | |
if (index === -1) return this.board; | |
for (let possibility = 1; possibility < 10; possibility++) { |
This file contains hidden or 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
const fs = require('fs'); | |
let words = fs.readFileSync('/usr/share/dict/words', 'utf8') | |
.split('\n'); | |
let board = [ | |
'moronqisioteqwo', | |
'gdouchebagopzay', | |
'frnvfkttdnjddsk', | |
'eawtcolcaeoksru', | |
'lsiiwamchnwurcg', | |
'isddraecyipdjoa', |
This file contains hidden or 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 { comments } from "./mock-response.json"; | |
const mockResponse = (response) => { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve({ | |
success: 200, | |
json: () => | |
new Promise((resolve) => { | |
return resolve(response); |
OlderNewer