- is
- this
- markdown
This file contains 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
from itertools import permutations | |
# Program to solve IBM's Ponder This puzzle for January 2024. | |
# https://research.ibm.com/haifa/ponderthis/challenges/January2024.html | |
# | |
# Using each of the numbers 1–16 exactly once, fill in the blank squares | |
# in the grid below, so that the 16 equations are true. | |
# | |
# ┌───┬───┬───┬───┬───┬───┬───┐ | |
# │ │ + │ │ − │ │ − │ │ 5 |
This file contains 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
; Inputs: A and B are bit-strings of length N, | |
; right-justified in EAX and EBX respectively; | |
; N ≤ 30 is in ECX, and A ≠ B. | |
; | |
; Output: ESI/EDI (a fraction) is the probability | |
; that bit-string A beats bit-string B. | |
Magic: | |
PUSH EAX | |
PUSH EBX |
This file contains 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
from itertools import combinations | |
from string import ascii_uppercase | |
states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", | |
"Colorado", "Connecticut", "Delaware", "Florida", "Georgia", | |
"Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", | |
"Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", | |
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", | |
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", | |
"New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", |
This file contains 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 numpy as np | |
# Compute expected number of turns to complete a snakes & ladders | |
# track of length n, given a set of portals (snakes and ladders), | |
# which are both represented as lists of pairs (start, end). | |
# It's ok to pass lists of [start, end] instead of pairs (start, end). | |
def E(n, portals): | |
portal_map = {k: k for k in range(n)} # identity map | |
portal_map.update(portals) |
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <time.h> | |
typedef uint8_t byte; | |
typedef uint32_t quart; | |
typedef uint64_t pottle; |
This file contains 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
from fractions import Fraction | |
from functools import lru_cache | |
from itertools import * | |
def powerset(S): | |
return chain.from_iterable(combinations(S, r) for r in range(len(S)+1)) | |
@lru_cache(maxsize=512) | |
def p(S): # S is a frozenset so it can be cached | |
if len(S) == 0: |
This file contains 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
PAGE 58,132 | |
;---------------------------------------------------------------------------- | |
; Hier sind der neu SETUP komputerprogramm. | |
;---------------------------------------------------------------------------- | |
.386P | |
FALSE EQU 0 |
This file contains 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 | |
N = 2018 | |
trials = 10000 | |
def connect(wires): | |
loops = 0 | |
while wires > 1: | |
v, w = random.randrange(wires), random.randrange(wires) | |
if v == w: |
This file contains 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
# Determine how many ways the US election could end in electoral tie. | |
# Respsonse to https://twitter.com/daveinstpaul/status/792788962230226944 | |
from functools import lru_cache | |
votes = [9,8,3,3,8,18,11,4,7,6,10,7,55,11,20,9,16,4,7,10,9,3,6,3,3,10, | |
11,29,3,38,16,5,6,4,6,3,4,4,13,20,14,12,11,5,5,6,29,10,6,15,3] | |
@lru_cache(maxsize=10000) | |
def count_ties(subtotal, votes): |
NewerOlder