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
while true | |
print "Compute nth Fibonacci number. (n < 94): " | |
input = gets | |
if input.nil? | |
puts "\nExiting." | |
exit | |
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
const PI_OVER_2 = Math.PI / 2 | |
function cos(x) { | |
const x_sq = x * x | |
let next_add = false | |
let sum = 1 | |
let n = 1 | |
let d = 1 | |
let term = 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
function Trie() { | |
this.trie = new Map | |
} | |
Trie.prototype.add = function (s) { | |
let branch = this.trie | |
for (let i = 0; i < s.length; i++) { | |
const c = s[i] | |
if (!branch.has(c)) { | |
const next_branch = new Map |
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
/** | |
* @param {number[]} nums | |
* @param {number} k | |
* @param {number} t | |
* @return {boolean} | |
*/ | |
function containsNearbyAlmostDuplicate(nums, k, t) { | |
const tree = [] | |
for (let i = 0; i < nums.length; 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
const min_pq = () => { | |
const heap = [] | |
const index_map = new Map | |
function get_set_for(x) { | |
if (index_map.has(x)) { | |
return index_map.get(x) | |
} else { | |
const s = new Set | |
index_map.set(x, s) |
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 ComboBoxStyle = styled('div')` | |
display: flex; | |
align-items: center; | |
select { | |
font-size: 0; | |
background: transparent url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'%3E%3Cpath fill='%23414850' d='M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z'/%3E%3C/svg%3E") no-repeat right .5rem center; | |
background-size: 50%; | |
height: .5rem; | |
width: 1rem; |
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 * as React from 'react' | |
import $, { Stream, Subscription } from 'xstream' | |
import { createChangeEmitter, Emitter } from 'change-emitter' | |
import { UnsubscribingProducer, StreamComponentState } from '../typings' | |
type Homo<I, O> = (input: I) => O | |
export function event() { | |
const emitter = createChangeEmitter() |
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
#!/bin/sh | |
remote="$1" | |
url="$2" | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
yarn lint || exit 1 | |
done |
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 is_palindrome_permutation { | |
const buckets = new Map | |
const is_even = string.length & 1 === 0 | |
for (let i = 0; i < string.length; i++) { | |
const c = string[i] | |
if (buckets.has(c)) { | |
buckets.set(c, !buckets.get(c)) | |
} 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
// lists and arrows are both constructed from reducing from array with cons/compose. | |
// they are monoids. | |
const flip = f => (y, x) => f(x, y) | |
const is = c => x => x === c | |
const get = k => x => x[k] | |
// lists |