Skip to content

Instantly share code, notes, and snippets.

View yoniLavi's full-sized avatar
:octocat:
Figuring things out

Yoni Lavi yoniLavi

:octocat:
Figuring things out
View GitHub Profile
@yoniLavi
yoniLavi / discrete_probability.py
Last active June 30, 2025 19:43
Discrete probability distribution simulator from first principles, written with the help of Claude Sonnet 4
"""
Discrete probability distribution simulator with proper dependency tracking.
This module implements discrete probability distributions from first principles,
correctly handling complex dependencies between random variables.
Examples:
>>> die = RandomVariable.die()
>>> coin = RandomVariable.coin()
@yoniLavi
yoniLavi / o1-reasoning-on-cryptic-clue.md
Last active January 29, 2025 12:21
Testing ChatGPT o1 on the cryptic crossword clue "Wicked ox tempts shark to final location (1,5,3,4)"

Thought about cryptic crossword clues for 7m 4s:

Laying out the options I’m working through a cryptic crossword clue, analyzing synonyms, and considering anagrams and wordplay to uncover the answer.

Identifying an anagram OK, let me see. I’m thinking the cryptic clue suggests “OXTEMPTSSHARK” is an anagram. Trying different letter arrangements to find a common (1,5,3,4) phrase.

Identifying potential words I’m gathering info on the frequency of each letter. Using “A” as the starting letter, I’m considering a (1,5,3,4) phrase with available letters.

@yoniLavi
yoniLavi / working_with_lichess.ipynb
Created November 26, 2024 22:57
A basic example of working with the lichess bot API
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int trigPin = 9;
const int echoPin = 10;
const int ledPin = 3; // PWM pin for LED
// Adjust these values to match your desired range
@yoniLavi
yoniLavi / 7-segment-display.ino
Created October 16, 2024 19:37
A basic Arduino example of providing a digital reading of a potentiometer via a 7-segment display
// Potentiometer
int potPin = A0;
// 7-Segment Display
const int sA = 1;
const int sB = 7;
const int sC = 5;
const int sD = 4;
const int sE = 3;
const int sF = 2;
import pulp
import pandas as pd
warehouses = pd.Series({"Dublin": 300, "Cork": 200, "Galway": 200})
targets = pd.Series({"Belfast": 150, "Limerick": 250, "Sligo": 200})
costs = pd.DataFrame({
"Belfast": [16, 14, 13],
"Limerick": [18, 12, 15],
"Sligo": [11, 13, 17]
@yoniLavi
yoniLavi / avoid_collision.py
Created September 14, 2024 13:43
A slightly simplified version of the Webots collision detection example at https://cyberbotics.com/doc/guide/tutorial-4-more-about-controllers?tab-language=python
from controller import Robot, DistanceSensor, Motor
TIME_STEP = 64
SPEED = 3.14
PROXIMITY_THRESHOLD = 80
robot = Robot()
def setup_sensor(device_id):
sensor = robot.getDevice(f"ps{device_id}")
@yoniLavi
yoniLavi / sympy_laplace_transform.py
Created September 12, 2024 08:06
A clean example of approaching an ODE via a Laplace transform in Sympy
from sympy import symbols, Eq, laplace_transform
from sympy.physics.mechanics import dynamicsymbols
t, s, G, F = symbols('t s G F')
g, f = dynamicsymbols('g f') # type: ignore
# Equation: d^2g/dt^2 + 4dg/dt + 3g = 0.2 df/dt + 1.5f
eq_lhs = g.diff(t, t) + 4 * g.diff(t) + 3 * g # type: ignore
eq_rhs = 0.2 * f.diff(t) + 1.5 * f # type: ignore
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yoniLavi
yoniLavi / settings.json
Last active April 8, 2025 21:13
My VS Code settings
{
"css.format.newlineBetweenRules": false,
"debug.onTaskErrors": "debugAnyway",
"diffEditor.codeLens": true,
"editor.accessibilitySupport": "off",
"editor.autoClosingBrackets": "never",
"editor.autoClosingQuotes": "never",
"editor.copyWithSyntaxHighlighting": false,
"editor.dragAndDrop": false,
"editor.formatOnType": true,