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
-- Return a list of all combinations (i.e. order doesn't matter) of the given length. | |
-- Example: Given "abc" and 2 the answer is ["ab","ac","bc"] but order doesn't matter at either level. | |
combinations :: [a] -> Int -> [[a]] | |
combinations letters 0 = [[]] | |
combinations [] p = [] | |
combinations (letter : letters) n = combinations letters n ++ map (letter :) (combinations letters (n -1)) | |
main = print $ combinations "abc" 2 |
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 Data.List (find) | |
data Family = Family | |
{ person :: String, | |
mother :: String, | |
father :: String | |
} | |
deriving (Show, Eq) | |
relatedFamilyData :: [Family] |
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
// Invokes functions that are given as arguments in succession. | |
// Works like flow/pipe/compose, but all functions are given an additional "state" argument | |
// which may contain any additional values that are needed by all functions e.g. configuration. | |
// Inspired by the Reader monad. | |
const readerCompose = (functions) => functions | |
.reduce((fn1, fn2) => (state) => (...args) => | |
fn2(state)(fn1(state)(...args)) | |
) | |
const state = { |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>random pattern generator</title> | |
<!--<link rel="stylesheet" href="style.css" /> --> | |
</head> | |
<body id="home"> | |
<canvas id="canvas" width="1000px" height="1000px"></canvas> |
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
/* | |
Given two arrays of elements, say 1 and 2, write a function that finds the | |
common elements between them and returns the following three arrays: | |
- An array containing all elements in 1 that aren't also contained in 2. | |
- An array containing all common elements that are both in 1 and 2. | |
- An array containing all elements in 2 that aren't also contained in 1. | |
*/ | |
// Simple solution - O(n^2) |
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 array = [1, 2, 10, 5, 4, 0, 9, -1, 3]; | |
const insertionSort = (array: Array<number>) => { | |
for (let i = 1; i < array.length; i++) { | |
const newElement = array[i]; | |
const prevElement = array[i - 1]; | |
// If the current element is smaller than the previous one, | |
// we have to insert it in its proper place | |
if (prevElement > newElement) { | |
console.log('Found an unordered element',newElement) |
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://adventofcode.com/2020/day/1 | |
After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you. | |
The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room. | |
To save your vacation, you need to get all fifty stars by December 25th. | |
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck! | |
Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up. | |
Specifically, they need you to find the two entries that su |
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 maxCachePeriod = 3000; | |
const cache = new Map(); | |
setInterval(() => { | |
const now = +new Date(); | |
cache.forEach((value, key, map) => { | |
if (now - value.time > maxCachePeriod) { | |
cache.delete(key); | |
} | |
}); | |
}, maxCachePeriod); |
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/bash | |
# uses ripgrep to search for all matches of a given phrase in the current directory and open all | |
# files which contain matches in vim | |
function rv() { | |
vim -p $(rg -l "$1" | sed 'sa\\a/ag') -c "/$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
[alias] | |
switch = "!branchesString=$(git for-each-ref --sort=-committerdate --count=10 --format='%(refname:short),' refs/heads/) && branches=(${branchesString//,/ }) && for i in ${!branches[@]}; do echo \"$i - ${branches[$i]}\"; done && read -p which: branch && git checkout ${branches[$branch]}" |
NewerOlder