Archive for March, 2019

Some random programs I wrote (Part II)

March 6, 2019

Unrelated note: I turned 30 today and am currently at the final stage of deciding between offers for my next career (very exciting times & stay turned for updates =) )

42 profile as of March 6th, 2019

Somewhere in the middle of my time at 42, I took a “C++ piscine”, graduated from C to C++ and started writing object oriented programs. This post will give a pictorial outline of a few of those later projects. Again, most of those are 2-man projects I shared with my coding companion Liam Dehaudt.


This is an off-the-galaxy project “custom created” for us by a guy named Gaetan who run the school here. The goal was to understand this paper, which presents a consensus algorithm comparable to block-chain and implement a small scale version of the system.

Hashgraph visualizer in action (intentionally slowed down for clarity)

In the example above we have 6 nodes in the network, they randomly ‘gossip’ to each other with gossips potentially carrying a payload. Every local graph is then updated through the gossip. New nodes representing the event of the gossip is added on (blue nodes), every ’round’ there is a layer of ‘witness nodes’ (red); when witness was well know they become ‘famous’ (yellow) and the famous witnesses then vote for the authenticity of other nodes (once nodes are approved, they turn green and is then logged into the database). If nodes are not approved (i.e. error or fraud), they will turn grey and a waring will be printed. We also implemented our own MD5 hashing algorithm to use for all connection and signatures.

Museum of Shaders

A cool graphics project exploring the fantastic world of openGL fragment shaders (i.e. using a single shader applied to a quad to render things line 3 dimensional fractals). We place shaders in a museum environment (Which I definitely did not steal from the British Museum Elgin marble room) by using billboards to fake 3D and switch between two different display/perspective systems when far away and close to the shaders.

As some may have picked up, I was able to put in some not-so-subtle references from mathematics, the shaders exhibited are:

  • Mandelbox (the scale multiplier changes over time)
  • Mandelblub
  • Sierpinski’s tetrahedron
  • IFS based on Sierpinski symmetry
  • Semi-transparent Quaternion Julia set (4th dimension evolves over time)
  • Cloud with Volumetric ray-marching
  • Structure generated by Kleinian group in 3D torus
  • Galaxy (2D shader)
  • Kaleidoscope (2D shader with octagon symmetry)

Was a lot of fun playing with shader ray-marching to get them to work =) & in the process I have discovered some amazing online fractal and shader enthusiast communities such as ShaderToy.

Voxel World

Sunset from a mountain top

Generated infinite Minecraft style terrains using a few layers of Perlin noise. Optimized in openGL by making block meshes etc. I had lots of fun making landscape look natural, included snow, mountains, grass, sand, water, trees and caves.

Moving, running or gliding through the world


An AI capable of playing the classical board game Gomoku along with an implementation of the game mechanisms and UI.

We implemented a version of minimax algorithm with Alpha-Beta pruning enhanced by killer heuristics. One of the rather unconventional idea used was, to reach higher search depth and take full advantage of the entire game time as a real player would, I decided to make a parallel thread which continuously search and hash moves back-stage while human player is thinking, then we are able to cap the return time at 0.5 seconds once player placed a stone by iterative deepening.


Some random programs I wrote (Part I)

March 6, 2019

In late April 2018, I officially went onboard 42 as a ‘cadet‘ and have since ‘climbed the ranks’ all the way to ‘captain‘ by completing various programming projects in the ‘galaxy‘. It has been a uniquely addictive process. I decided to write a post to outline some of the projects as well as sharing my plans on what’s next. Please also feel free to visit my Github for the source code and more detailed descriptions of the projects.

The galaxy

Below are a few of my personal favorites, ordered roughly chronologically.

Note: many of below are team projects done in pairs or triples, I’ll credit my awesome friends and teammate Liam Dehaudt and Charlie Gleason here =)


This was one of the first projects in the curriculum. The goal is to render various fractals in \mathbb{C} in real-time by taking mouse position as parameter. Parallel threads are used to speed up the rendering.

After completing the basic ‘stage set-up’ and the required Mandelbrot and z^2 + c. I had lots of fun coming up with color schemes and implementing rational function Julia sets such as those with locally connected Julia set homeomorphic to the Sierpinski carpet:

As well as those that has a hyperbolic symmetry similar to that of the Poincare disk:


This is an optimal transportation puzzle where one needs to find the minimal number of steps to transport a fixed amount of ants from one point to another through a graph. I had fun designing a retro-style ascii visualizer on top of the algorithm =)

We re-formulated the problem into a max-flow problem on a derived directed graph (we double all vertices and edges and form a larger graph) to apply the Ford–Fulkerson theorem. Project the resulting parallel paths to the original network and resolve overlaps. Then we queue the ants in the resulting set of disjoint paths depending on the length of each path. The result guarantees optimum solution as long as the number of ants is greater than the sum of lengths of paths from Ford–Fulkerson.

A simple example where the flow solution would result in overlapping paths and resolving overlap was required and the queuing can be seen observed


We made a reproduction of the Core War game. Including full implementation of assembly compiler, virtual machine and GUI.

Virtual Machine in action (4 worrier mode)

Core War is a 1984 programming game created by D. G. Jones and A. K. Dewdney, inspired by a malicious virus written in the 80’s. To deal with the self-replicating virus, a white hat hacker invented Reaper. It was a virus designed to spread and eliminate the malware.

The idea was simple. You compete by designing viruses to overtake a computer. You win by protecting your own program and overwriting your opponent’s programs. This is all happening on a virtual machine.

Particle System

An openCL and openGL simulation of movement of millions of particles in space in various gravitational modes. Used GPU for parallel computing.

Change gravity strength

Note: Due to the GPU restrictions, this project records with significant quality and performance loss, highly recommend trying it out!

…More to come in Part II…