Python

To see more tidbits of code, visit my Github profile here. Below are a few I like:

Magic Hexagon

This code isn't my best work, but it gives you the answer to the magic hexagon. I had a wooden puzzle that I'd been trying to solve for months. I resolved not to look up the answer so wrote this code instead.

Connect 4

Using Reinforcement Learning, I created an Agent that can be trained in Connect4. It competes against an opponent that's about as good as your nine-year-old cousin: it makes winning moves if it can, and blocks the Agent from winning if applicable. Since there are so many combinations of Connect4 games, you have to set the number of training games pretty high for it to start winning. And this will take a while...so improving this code is definitely a future project.

Knight Moves

Given inputs x and y representing two positions on a chess board (0-63), this code will output the (least) number of moves it would take a knight to travel from position x to y. This problem was on foobar (still waiting to hear back from you, Google...)

Shortest Path

Another foobar problem, and a classic. Given a matrix of 1's and 0's, this code will output the length of the shortest path from the top left of the matrix to the bottom right. 0's represent open space, and 1's represent walls; BUT, you are allowed to knock down one wall in your quest to find the shortest path. Intriguing, isn't it.

Vpython

For each physics unit in high school, we had to solve a problem based on what we'd just learned. I wrote a program in Vpython for each unit that would simulate the scenario. Press its play arrow to run a program! You can change most of the parameters in each code. If it's hard to see the simulation, use two fingers to zoom out.

Projectile Motion

The scenario is thus: a drone flying straight up carries a water balloon over a field. There is a cannon on the other side of the field. You must input the distance between drone and cannon, the angle at which the cannon fires, and the time after takeoff before the drone releases the balloon. The simulation will tell you at what time to fire the cannon to hit the balloon.

Spring Ramp

A block sits on a ramp with a spring at the bottom – you input the ramp's angle. You can adjust the block's mass, the spring constant, and the static and kinetic coefficients of friction, and see how long it takes the block to stop moving.

Slingshot

By far my favorite one here. It reenacts a classic movie scene: the hero dives to save a friend from falling to their death. Fortunately, the friend has a parachute. You have to fire the slingshot by clicking.

Blocks on Ramp

Block A sits attatched to a spring, and it slides down a ramp, hitting block B (which has a stopper attatched). Both blocks end up as close to the end of the ramp as possible, no matter the inital configuration. You can adjust all the parameters.

Batman

Batman fires a grappling hook and swings on it. You can adjust the variables to try to get him to swing farther, but be careful not to exceed the tensile strength of the rope.