Skip to content

Instantly share code, notes, and snippets.

View wimglenn's full-sized avatar
💭
🦡🦡🦡🦡🍄🍄🦡🦡🦡🦡🦡🦡🐍

Wim Jeantine-Glenn wimglenn

💭
🦡🦡🦡🦡🍄🍄🦡🦡🦡🦡🦡🦡🐍
View GitHub Profile
import random
import re
import timeit
import matplotlib.pyplot as plt
from collections import Counter
def sum_digits_math(n):
"""from https://stackoverflow.com/a/14940026/674039"""
r = 0
@wimglenn
wimglenn / q15_2.py
Created May 20, 2021 03:26
fill in presized lists instead of appending
def duel(a, b):
fa = 16807
fb = 48271
d = 0x7fffffff
count1 = 0
a4 = 5000000*[0]
b8 = 5000000*[0]
na = nb = 0
for i in range(40000000):
a = (a * fa) % d
@wimglenn
wimglenn / q15_1.py
Last active May 20, 2021 03:27
original implementation
def duel(a, b):
fa = 16807
fb = 48271
d = 0x7fffffff
count1 = 0
a4 = []
b8 = []
for i in range(40000000):
a = (a * fa) % d
b = (b * fb) % d
# timing of pkgutil and importlib.resources loaders from https://github.com/wimglenn/resources-example
# Python 3.8.5 on linux
>>> from myapp.example2 import func as pkgutil_loader
>>> from myapp.example4 import func as importlib_resources_loader
>>> timeit importlib_resources_loader()
392 µs ± 329 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
>>> timeit pkgutil_loader()
200 µs ± 230 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
>>> timeit importlib_resources_loader()
@wimglenn
wimglenn / share_markdown.user.js
Created February 19, 2020 16:08 — forked from kms70847/share_markdown.user.js
For each Stack Overflow question, adds an additional box to the "share" button, containing a link with markdown
// ==UserScript==
// @name Share Markdown (Stack Overflow)
// @namespace about:blank
// @include http://stackoverflow.com/questions/*
// @include https://stackoverflow.com/questions/*
// @version 6
// @grant none
// ==/UserScript==
function make_input(text){
@wimglenn
wimglenn / share_markdown.user.js
Created February 19, 2020 16:08 — forked from kms70847/share_markdown.user.js
For each Stack Overflow question, adds an additional box to the "share" button, containing a link with markdown
// ==UserScript==
// @name Share Markdown (Stack Overflow)
// @namespace about:blank
// @include http://stackoverflow.com/questions/*
// @include https://stackoverflow.com/questions/*
// @version 6
// @grant none
// ==/UserScript==
function make_input(text){
@wimglenn
wimglenn / quine_aoc2019-9.log
Created December 9, 2019 21:54
AoC 2019 day 9 quine
AoC 2019 day 9 quine: 109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99
0 op_offset ip=0 opcode=00109 offset=0 args=[1] {0: 109, 1: 1, 2: 204, 3: -1, 4: 1001, 5: 100, 6: 1, 7: 100, 8: 1008, 9: 100, 10: 16, 11: 101, 12: 1006, 13: 101, 14: 0, 15: 99}
1 op_output ip=2 opcode=00204 offset=1 args=[0] {0: 109, 1: 1, 2: 204, 3: -1, 4: 1001, 5: 100, 6: 1, 7: 100, 8: 1008, 9: 100, 10: 16, 11: 101, 12: 1006, 13: 101, 14: 0, 15: 99}
2 op_add ip=4 opcode=01001 offset=1 args=[100, 6, 100] {0: 109, 1: 1, 2: 204, 3: -1, 4: 1001, 5: 100, 6: 1, 7: 100, 8: 1008, 9: 100, 10: 16, 11: 101, 12: 1006, 13: 101, 14: 0, 15: 99}
3 op_eq ip=8 opcode=01008 offset=1 args=[100, 10, 101] {0: 109, 1: 1, 2: 204, 3: -1, 4: 1001, 5: 100, 6: 1, 7: 100, 8: 1008, 9: 100, 10: 16, 11: 101, 12: 1006, 13: 101, 14: 0, 15: 99, 100: 1}
4 op_jump_f ip=12 opcode=01006 offset=1 args=[101, 14] {0: 109, 1: 1, 2: 204, 3: -1, 4: 1001, 5: 100, 6:
@wimglenn
wimglenn / intcomputer.py
Created December 9, 2019 18:46
IntComputer class for Advent-of-Code 2019
import logging
from collections import defaultdict
from collections import deque
# logging.basicConfig(level=logging.INFO, format=" %(message)s")
log = logging.getLogger(__name__)
# "parameter modes"
POSITION = 0
@wimglenn
wimglenn / numpy wat
Created June 26, 2018 20:10
numpy wat
>>> import numpy as np
>>> import builtins
>>> np.random.randn(3,3)
array([[-0.24401213, -0.19773938, 0.47278806],
[-0.6083566 , -0.65160561, 0.78145811],
[ 0.14546934, -0.86849935, 2.07570471]])
>>> np.empty((3,3)) # sign loss
array([[0.24401213, 0.19773938, 0.47278806],
[0.6083566 , 0.65160561, 0.78145811],
[0.14546934, 0.86849935, 2.07570471]])
@wimglenn
wimglenn / gold tag badgers (22 Jun 2018)
Created June 22, 2018 22:24
gold tag badgers (22 Jun 2018)
{
"c#": 595,
"java": 531,
"javascript": 447,
"python": 422,
"c++": 404,
"php": 272,
"android": 268,
"jquery": 247,
"c": 175,