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
// Create a large array of 5-letter words in a words.json array like so { "solutions": [...] } | |
import { solutions } from "./words.json"; | |
/** | |
* Solves Wordle in as few tries as possible. | |
* | |
* @example | |
* const solver = new WordleSolver(optionalStartingList); | |
* | |
* // User enters 'later', gets a score of [grey, grey, hit, misplaced, misplaced]: |
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 US_ADULT_POPULATION = 245e6; | |
const populationSize = US_ADULT_POPULATION; | |
const defaultSampleSize = 15000; | |
type Individual = number; | |
type Population = Individual[]; | |
type Sample = Individual[]; | |
main(); |
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 React, {useState} from 'react' | |
// Custom hook that manages local state for a counter. | |
export function useCounter(initialValue) { | |
const [count, setCount] = useState(initialValue) | |
const increment = () => setCount(count => count + 1) | |
const decrement = () => setCount(count => count - 1) | |
const reset = () => setCount(initialValue) | |
return { | |
reset, |
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 React from 'react'; | |
function Spenses({ items }) { | |
function deleteItem({ id, amount }) { | |
// Delete the item. | |
} | |
return ( | |
<> | |
{items.map((item, index) => ( |
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
#!/usr/bin/env node | |
const fs = require('fs'); | |
const models = require('../models'); | |
for (const model in models) { | |
const tableName = models[model].tableName; | |
let defaultValue = ''; | |
let onUpdate = ''; |
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
fizzes = cycle ["", "", "Fizz"] | |
buzzes = cycle ["", "", "", "", "Buzz"] | |
fbs = zipWith (++) fizzes buzzes | |
nums = map show [1..] | |
fizzbuzz n = take n (zipWith max nums fbs) | |
-- Usage: | |
-- fizzbuzz 3 | |
-- -> ["1", "2", "Fizz"] |
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 { Schema, arrayOf } from 'normalizr' | |
let userSchema = new Schema('user', options) | |
let nbhdSchema = new Schema('nbhd', options) | |
let itemSchema = new Schema('item', options) | |
let commentSchema = new Schema('comment', options) | |
let nbhdsSchema = arrayOf(nbhdSchema) | |
userSchema.define({ | |
nbhds: nbhdsSchema |
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
module HangmanGuesser (main) where | |
import Data.List (intersect, nub, sort) | |
import Data.Char (toLower) | |
import Data.Tuple (swap) | |
import Data.Map as M (Map, fromListWith, toList) | |
main = do | |
corpus <- readFile "web2" |
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 random | |
american_adult_population = int(245e6) | |
# Warning: This array is HUGE! | |
# The array is just the numbers from 0 to 245,000,000 | |
usa_array = range(american_adult_population) | |
actual_average = float(american_adult_population / 2) | |
sample_amount = 1500 |
NewerOlder