Skip to content

Instantly share code, notes, and snippets.

View jmccardle's full-sized avatar

John McCardle jmccardle

View GitHub Profile
0eNrtXVuP27gV/isLAX0p7F3xTg6CAnt7bR/StyIYaGzOjBBbMmQ5TRrMfy9lz0S0RIo8dDyopnnZ7PjykTznfOfCQ9Ffs7vNQe+asmqzm69ZuaqrfXbzr6/Zvnyoik33Wvtlp7ObrGz1NltkVbHt/tq3utgu20NzV1Y6e1pkZbXWn7Mb9LSI+G7dFA962RbVR+ur+OnDItNVW7alPs3h+MeX2+qwvdONwXYjLLJdvTdfqqtuRAO0xAr/zBbZF/O/nLKfmRljXTZ6dfoM7qY4gMbfoHelmbELEvWQwkA6QEgYJA+C0OhFSgVcJAvOz4b0zI+HQWQQRIRBRBBEhkF4EETFi5sBxY3y8ARZcIIIhVFoGCVs4JKEUcIWLnEYBWDiUB6jCBsPExlFGHmYyShs5SLMNxQ2cxEmHIq3cxstzneG7VyE2YzDdi7CdMY4fp1QPuOw9YswnzENo4T5jMN2LsJ8xmE7F2E+YxEvcwSVeYT1h/mMVRglzGeSR6+TQzlEwtbPw76ChL08D/sKErZzHuYzoUnZGvagsaS0yIfGk6K+D00kxTMfmkzy1D40leQPPWg0T2K6Dw0l8Qkf+WTqlOpEqH33KdT9p9Fru2wozV/cFBVPzsGxp5SZTv2J9KyFxMNZ+bEXjgLgaBiOAeAiFsvj4azI74UTALiIxUoAXB6GU/FwPLxY1lNoq9flYbvUG2PHTbla7uqN2/z6QE5OwaTS5cPjXX1oujKZkQ+ucVCafRPPtHGaffvgCFgKVi3nlEK+YMIpiEQq+WaeSCUfXCKVfHACLFerBHFb14Ipp1xlGmt9M1fwmePpmYsFx66Z8zzNQXhmzlGag/DBYbAgOBsKIjI6UmRN4BguRRcuh4JUC+6kFu9Z/KiLdqk/rx6L6sG8FXAyuXPhFIBm+xg3GoOg0RAah6AFVyouUnEOTIDOVYwwd+jYWJ15w6lkeb5079Zmz0bsiX1cRUKhIJTII6HyMBSKg7LqCi8UjoSSYSgC2d3EyoNCIyckwhNikVA
class BinaryNode:
__slots__ = ("value", "left", "right")
def __init__(self, value=None, left=None, right=None):
self.value = value
self.left = left
self.right = right
def __repr__(self):
return f"<BinaryNode value={self.value}; {1 if self.left else 0 + 1 if self.right else 0} children>"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# See this diagram: https://i.redd.it/41iyyfdaliab1.png
from itertools import permutations
for i, perm in enumerate(permutations([1,2,3,4,6,8,9])):
a, b, c, d, e, f, g = perm
if (a + d + g + f) +1 == (b + d + e + g) -1 == (c * e * f * g +1)**0.5:
print(f"\n{i}. Solution: a = {a}, b = {b}, c = {c}, d = {d}, e = {e}, f = {f}, g = {g}, x = {(a+d+g+f)+1}")
elif i % 10 == 0:
print(f".", end='')
# See diagram: https://i.imgur.com/UWDrqcH.png
# We need 8 equations to solve the diagram, but I can only come up with 5.
# For three more equations, we will assume a value for X, A, and D.
# If sympy times out, we will cancel the attempt.
# Values for X: 7 choose 4, 35 possible values.
# Values for A: 7.
# (Naive) Maximum loops: 7*35 = 245.
# (actual) maximum loops: 4 * 35 = 140. A has to be in the circle for the solution for X we're using.
# See diagram: https://i.imgur.com/UWDrqcH.png
from itertools import permutations
for i, perm in enumerate(permutations([1,2,3,4,5,6,7])):
a, b, c, d, e, f, g = perm
if (a + d + g + f) / 2 == (b + d + e + g) / 3 == (c + e + f + g) / 4:
print(f"\n{i}. Solution: a = {a}, b = {b}, c = {c}, d = {d}, e = {e}, f = {f}, x = {(a+d+g+f)/2}")
else:
print(f"{i} ", end='')
# (Major issues) - not enough equations to solve this SOE!
# See diagram: https://i.imgur.com/UWDrqcH.png
# We need 7 equations to solve the diagram, but I can only come up with 5.
# For two more equations, we will assume a value for X and A.
# If sympy times out, we will cancel the attempt.
# Values for X: 7 choose 4, 35 possible values.
# Values for A: 7.
# (Naive) Maximum loops: 7*35 = 245.
import pandas as pd
def region(row):
#print(row)
state = row["state"]
if state in ("FL", "GA"): return "South"
elif state in ("CA", "WA"): return "West"
elif state in ("MT", "MN"): return "Central"
elif state in ("NY", "ME"): return "North"
else: return "Unknown"
# Pico W GPIO-over-website test
# thanks to https://www.petecodes.co.uk/creating-a-basic-raspberry-pi-pico-web-server-using-micropython/ for the kickstart
import network
import socket
import time
from machine import Pin
import secrets
# secrets.py defines SSID and PASSWORD variables, used on line 12 - don't expose your SSID/passphrase to github, please
import machine
wlan = network.WLAN(network.STA_IF)
# knights and knaves
class Meta(type):
def __repr__(cls):
return f'<{cls.__name__}>'
class Knight(metaclass = Meta):
pass
class Knave(metaclass = Meta):