Skip to content

Instantly share code, notes, and snippets.

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
}, {
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
# 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
# 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
<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);
}
{#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}
<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);
}
<svg id="chartSVG" viewBox="0,0,1000,2000">
<image width="1000px" height="2000px" style="opacity:0.2;" href="/babies-pixabay.png">
</image>
{#if letterCounts.length > 0}
{#each letterCounts as d, i}
<rect x = 0 y = {yScale(d.letter)} width = {xScale(d.count)} height = {yScale.bandwidth()}
in:fly="{{ x: -1000, duration: 1000, delay: 1000*i}}"></rect>
<text class="bar-label" x = {xScale(d.count) + 15} y = {yScale(d.letter) + yScale.bandwidth()/2}
in:fly="{{ x: -1000, duration: 1000, delay: 1000 * i }}">
{d.letter}: ({Math.round(d.count / totalBabies * 100)}%)
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<svg id="chartSVG" viewBox="0,0,1600,3200" width="1600"
style=" max-width: 100%;
font-family: Nunito, sans-serif;
border: 1px solid black;
background: radial-gradient(ellipse at bottom right, rgba(137,207,240,1) 20%, rgba(244,194,194,1) 70%);">
<image width="1600px" height="3200px" style="opacity:0.2;" href="babies-pixabay.png">
</image>
const totalBabies = letterCounts.reduce((a, b) => a + b.count, 0);
const smallCounts = {letter: "other", count: 0, otherLetters: ""}
for(let i = 25; i>=0; i--){
if(letterCounts[i].count < 0.015*totalBabies){
smallCounts.otherLetters += `${letterCounts[i].letter},`;
smallCounts.count += letterCounts[i].count;
letterNames["other"] = letterNames["other"].concat(letterNames[letterCounts[i].letter])
letterCounts.splice(i,1)
}
}