Skip to content

Instantly share code, notes, and snippets.

@Robochu
Robochu / e.py
Created December 19, 2023 22:29
Some ways of calculating pi and e that I came up with. None of these are original; these are just rediscoveries of existing methods.
# Approximate e using bisection.
import math
ITERS = 25
H = 2 ** (-26)
l = 2
m = 3
r = 4
@Robochu
Robochu / kusat.py
Last active December 19, 2023 02:06
An optimal 2x2 Rubik's cube solver that uses Z3's SAT solver under the hood.
# kuSAT - an optimal 2x2 Rubik's cube solver that uses Z3's SAT solver under the hood
#
# Terminology:
# - Face := one of the 6 sides of a cube. A common mistake is to try to solve a Rubik's cube one side at a time, when
# it should be solved one piece (or more) at a time.
# - Piece := one of the 8 corners of a 2x2 Rubik's cube. A Rubik's cube can be thought of as a collection of
# of independent pieces that move from location to location based on a set of rules. A piece can be
# identified using 3 faces. For example, ULB is a piece that would intersect the U, L, and B faces if the
# cube was in its solved state.
# - Location := one of the 8 places that a corner can be at. Similarly to a piece, a location is also identified using
@Robochu
Robochu / zinder.zig
Last active July 31, 2023 19:17
Fixed-point iteration brute-force finder.
//! A brute-force algorithm for finding a fixed-point iteration formula for an arbitrary constant. It can be used to
//! find the Babylonian method for finding the square root of a number, or to find a way to divide using addition,
//! subtraction and multiplication. More complex constants like pi are already too much for this algorithm, so overall
//! it's pretty useless.
//!
//! Tested with Zig 0.11.0-dev.4191+1bf16b172.
const std = @import("std");
fn neg(a: f64) f64 {
@Robochu
Robochu / arrow_easy.zig
Last active July 31, 2023 19:18
Exponential Idle arrow puzzle easy/medium difficulty brute-force optimal solvers.
//! A brute-force optimal solver for the easy difficulty of the "Arrow" minigame from the game "Exponential Idle".
//! Exponential Idle: https://conicgames.github.io/exponentialidle/
//!
//! Usage:
//! arrow_easy <board>
//! where <board> is 9 digits from 1 to 4 describing the board. To easily get the required digits, click on the
//! settings icon when playing the minigame and change the display mode to "Numbers". The digits should be entered from
//! left to right, top to bottom. For example, the board
//!
//! 1 3 3