Skip to content

Instantly share code, notes, and snippets.

@pochmann
pochmann / solve.py
Created August 7, 2022 00:02
Find all sets of five Wordle words without repeated letters
import glob
import numpy as np
from itertools import combinations
from time import time
t0 = time()
words = []
for file in glob.glob('wordle*'):
with open(file) as f:
for word in f.read().split():
from math import factorial
from re import sub
def calc(expression):
expression = expression.replace('^', '**')
expression = expression.replace('/', '//')
expression = sub(r'(\w+)!', r'factorial(\1)', expression)
return eval(expression)
# Numbers for certain cases (always sideSubsets * variationInsideSolvedsides * variationInRest)
@pochmann
pochmann / BTMize_ChenSolutions.pl
Created July 17, 2014 13:11
Take solutions from Shuang Chen's 4x4x4 solver, "optimize" the reduction part for BTM by replacing consecutive moves on the same axis with as few equivalent moves as possible, and produce input files for Cube Explorer for optimizing the 3x3x3 part. It's messy, inefficient and possibly buggy, sorry, I'm a bit out of shape and didn't have much tim…
use v5.10;
sub invertMove {
my ($m) = @_;
return $m if $m =~ /2$/;
return "$m'" if $m !~ /'/;
$m =~ s/'//;
return $m;
}
@pochmann
pochmann / 3x3x3_simulator.py
Last active August 29, 2015 14:03
Check whether two 3x3x3 algorithms are equivalent by simulating their effects and comparing the results. I love this way to simulate these puzzles, no complicated data structures needed.
def sim(alg):
state = "UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR".split()
for move in alg.split():
perm = "FLBR FRBL FDBU FUBD URDL ULDR".split()['UDLRFB'.index(move[0])]
n = 2 + "2'".find(move[-1])
table = str.maketrans(perm, perm[n:] + perm[:n])
state = [p.translate(table) if move[0] in p else p for p in state]
return state
print(sim("D L2 B2 L2 R2 F2 R2 U2 R2 D' U' R' B F L' D R2") == sim("U R B F L D R2"))
@pochmann
pochmann / 4x4_scramble_rotator.py
Last active January 3, 2016 03:19
4x4 scramble rotation incorporation
import re
from string import maketrans
from collections import Counter
def rotations(scramble):
ori2alg = {'UDLRFB':''}
for side, wide, angle in re.findall(r'(\w)(w?)(\S?)', scramble):
a = "12'".find(angle) + 1
next_ori2alg = {}
for ori, alg in ori2alg.items():