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
import { comments } from "./mock-response.json"; | |
const mockResponse = (response) => { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve({ | |
success: 200, | |
json: () => | |
new Promise((resolve) => { | |
return resolve(response); |
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 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 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 Sudoku | |
def initialize board | |
@board = board | |
end | |
def solve! | |
num_index = @board.index('0') | |
return true unless num_index | |
('1'..'9').each do |possibility| | |
@board[num_index] = possibility |
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
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 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 BoggleBoard | |
attr_reader :num_rows, :num_cols | |
def initialize(board) | |
@board = board | |
@num_rows = @board.count | |
@num_cols = @board[0].count | |
end | |
def create_word(*coords) |
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 BoggleBoard | |
#your code here | |
end | |
dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], |
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 '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 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 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 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) |
NewerOlder