Skip to content

Instantly share code, notes, and snippets.

View jakelevi1996's full-sized avatar

Jake Levi jakelevi1996

View GitHub Profile
@jakelevi1996
jakelevi1996 / Solving Tchisla in Python.md
Last active August 11, 2022 22:37
Solving "Tchisla" in Python (WIP)

Solving "Tchisla" in Python

Solve problems from the Tchisla app in Python. Code is in the tchisla.py script below. Parameters for the problem being solved can be modified in the if __name__ == "__main__" block at the bottom of tchisla.py.

TODO:

  • Avoid creating strings for expressions until the values have been validated
    • This could involve passing the operator and child expressions to Solver._validate instead of the resulting expression, calculting the value using the Operator.operation attribute or Operator.__call__ method in Solver._validate, and then only creating the resulting expression (including creating its string using the Operator.get_string attribute) if the value is valid
  • Change target, n and n_count_target to command line arguments
  • Add more comments
  • Save dictionaries to file so that the
@jakelevi1996
jakelevi1996 / Notes on Python.md
Last active March 31, 2023 11:28
Notes on Python

Notes on Python

This is a collection of notes on Python, including useful links, useful snippets, Python implementations of algorithms, and notes on built-in and third-party modules.

TODO: migrate existing Python-related Gists into subsections of this Gist

Contents

@jakelevi1996
jakelevi1996 / Notes on C and C++.md
Last active March 30, 2022 17:41
Notes on C/C++
@jakelevi1996
jakelevi1996 / Notes on CUDA.md
Last active April 11, 2022 17:50
Notes on CUDA

Notes on Cuda

This Gist contains notes and useful links about programming in Cuda, a language based on C/C++ for general purpose programming on Nvidia GPUs. Much of these notes are based on the book "CUDA by Example" by Jason Sanders and Edward Kandrot. There is also an example Cuda program, notes on Thrust ("the CUDA C++ template library"), and miscellaneous topics.

Contents

@jakelevi1996
jakelevi1996 / .wordle_guesser.md
Last active February 22, 2022 10:25
Programs for making good word choices in Wordle

Programs for making good word choices in Wordle

This Gist contains a couple of Python scripts for making good word choices in the word-game Wordle.

The first script is dumb_wordle.py. It suggests what words to guess without taking into account the information returned by Wordle after each guess. According to this script, the 4 best initial guesses are "raise" (or alternatively "arise"), "clout", "nymph", and "badge". The first 2 guesses are good because they hit all 5 vowels, and the top 4 most common letters to appear in 5 letter words. This script uses the text file "words_alpha.txt" which can be downloaded from this GitHub repository, takes up 4.03 MB of disk space, and contains 370,103 words between 1 and 31 letters long (the only word in this list which is 31 letters long is "dichlorodiphenyltrichloroethane")

The second scr

@jakelevi1996
jakelevi1996 / Notes on Gitlab CI.md
Last active June 30, 2022 21:12
Notes on Gitlab CI
@jakelevi1996
jakelevi1996 / .Finding eigenvalues using simultaneous iteration.md
Last active December 18, 2020 13:14
Finding eigenvalues using simultaneous iteration

Finding eigenvalues using simultaneous iteration

This Gist describes simultaneous iteration, an eigenvalue algorithm for a symmetric NxN matrix A, which can be seen as a continuation of my previous Gist on a conceptually straightforward (albeit practically sub-optimal) eigenvalue algorithm for a symmetric NxN matrix. The algorithm presented here is more practically useful than the one presented in the previous Gist, although still not as practically useful as the implicit QR algorithm.

We want to find the eigenvalue decomposition for the symmetric matrix A; that is, we want to find matrices U and D which satisfy A == U * D * U^T , where U is orthogonal (IE U * U^T equals the identity matrix) and D is diagonal.

Using the power method, we can take an initial guess of an eigenvector u, and repeatedly replace u with the matrix-vector product `A *

@jakelevi1996
jakelevi1996 / .An impractical symmetric eigenvalue algorithm.md
Last active December 17, 2020 22:13
An impractical symmetric eigenvalue algorithm

An impractical symmetric eigenvalue algorithm

This Gist presents a conceptually straightforward (albeit practically sub-optimal) eigenvalue algorithm for a symmetric NxN matrix. It is inspired by "Chapter 7: Unsymmetric Eigenvalue Problems" of Matrix Computations, 4th Edition (Golub, Van Loan), and also uses Householder transformations/QR factorisation (see chapter 5 of Matrix Computations, or my earlier Gist), and the power method.

Let's say N = 5, and we want to find the eigenvalue decomposition for the 5x5 matrix A:

A =
[[ 9.776  2.782  2.048  0.418  3.66 ]
 [ 2.782 8.813 1.521 6.218 1.6 ]
@jakelevi1996
jakelevi1996 / .Making a gif from image files using PIL.md
Last active December 13, 2020 00:53
Making a gif from image files using PIL

Making a gif from image files using PIL

The pillow (fork of PIL, the Python Image Library) module presents a simple way to create a gif out of pre-existing image files, demonstrated below. More documentation can be found here. The intermediate image files which are generated by this Gist are not included directly, but can be generated by running the Python script.