Skip to content

Instantly share code, notes, and snippets.

<label for="year">
Select a year:
<select id="year" selected="2020" bind:value={selectedYear}
on:change="{
async () => {
letterCounts = [];
let response = await fetch(`names data/yob${selectedYear}.txt`);
let newFile = await response.text();
showBars(newFile);
}
{#each letterCounts as d, i}
<!-- code for bars and labels here -->
<g width = {xScale(d.count)} height = {yScale.bandwidth()}
style="transform: translate({xScale(d.count)/2}px,{yScale(d.letter) + yScale.bandwidth()/2}px); text-anchor: middle">
{#if d.words.length > 0}
{#each d.words as word}
<text x={word.x} y={word.y} style="transform: translate({word.x}, {word.y});
font-size: {word.size}px;
fill: {cat10colors[Math.floor(Math.random()*10)]}">
{word.text}
<script>
import {scaleBand, scaleLinear} from 'd3-scale';
import {csvParse} from 'd3';
import * as cloud from 'd3-cloud'
import { fly} from 'svelte/transition';
let years = [], selectedYear = 2020, textFile = "", nameData = [], letters = [], letterNames = {}, letterCounts = [];
for(let y = 1880; y<=2020; y++){
years.push(y);
}
# Solution to this puzzle:
# https://www.cantorsparadise.com/can-you-design-an-algorithm-to-solve-this-lovely-logic-puzzle-bc674be1ffbf
# This algorithm does not use Goldbach's conjecture (this would cut the running time in half at least!)
list0 = []
for i in range(2,2022):
for j in range(i+1,2023):
list0.append([i,j])
print("Number of possible pairs initially: "+str(len(list0)))
# Statement 1
import random
# generate all 2^n possible combos for the new row
def make_possible_rows(existing_rows, n):
new_rows = []
for i in range(len(existing_rows)):
new_rows += [existing_rows[i] + ['B']]
new_rows += [existing_rows[i] + ['R']]
if len(new_rows) == 2**n:
return new_rows
import random
import pandas as pd
def simulate(n):
trial_results = []
while True:
if len(trial_results) == n:
return trial_results
else:
cards = []
import random
import pandas as pd
results_df = pd.read_csv('results_tally_blank.csv')
results_df.set_index("Country", inplace=True)
group_A = [{
"team": "Netherlands",
"rating": 1716
}, {