Original Post on my Blog:

Basic Counterfactual Regret Minimization (Rock Paper Scissors) (pranav.ai)

Counterfactual Regret Minimization (Rock Paper Scissors)

Counterfactual regret minimization is an important concept in algorithmic game theory. It has made the creation of super-human poker AI possible and is fundamental for solving games of imperfect information. Today we will be implementing a rock paper scissors solver. Rock paper scissors is a useful introductory example as the game has a trivial solution (just play each option 33.333% of the time randomly). Solving rock paper scissors will lay the groundwork for solving more complex games (which we will do in future articles).

Note: All Code…

When I’m experimenting with models I typically prefer to have my math and code in the same place. Python is the language of choice for data scientists as it integrates seamlessly with Jupyter Notebook allowing for carefully placed analysis and explanations alongside code modules. However, recently I’ve been working on integrating a model into a piece of software where low latency is vital. C++ was the obvious answer in terms of language choice. I began looking for an interactive computing solution in C++ and eventually came across Xeus; a C++ kernel for Jupyter Notebook and Xeus-Cling; a C++ interpreter. …

Today we will be pricing a vanilla call option using a monte carlo simulation in Python. Monte Carlo models are used by quantitative analysts to determine accurate and fair prices for securities. Typically, these models are implemented in a fast low level language such as C++. However, for the sake of ease, we’ll be using Python.


Below is a list of pre-requisite knowledge to get the most out of this tutorial.


  • Calculus
  • Probability and Statistics
  • Very basic programming


  • Stochastic Processes
  • Stochastic Calculus or an introductory asset pricing class

Understanding The Math

Before diving into the code, we’ll cover some of the basic financial…

One of the trickiest parts about improving as a Poker player is finding high quality learning resources. There are numerous successful players over the years who have written books on their approaches to the game, yet Poker evolves so quickly that these books are often outdated within a few years.

During my time playing at Encore in Boston, I came across many older gentleman who were poker book junkies. They had read dozens of strategy books yet still struggled to beat relatively easy live games. This is because poker books that actually give quality information are very rare. …

Traversing binary trees is a fundamental skill required for coding interviews. Today I will teach you the main ways of traversing a binary tree. Each traversal style is associated with a specific pattern. Below is a quick reference. (All code examples are worked in python)

Binary Tree Traversal Cheat Sheet

Traversal->PatternIn-order left/center/rightpre-order center/left/rightpost-order left/right/centerlevel-order left to right

In-order -> Left/Center/Right

Pre-order -> Center/Left/Right

Post-order -> left/right/center

Level-order -> left to right


Pre-Order Traversal

A preorder traversal follows the center-left-right pattern. For the tree above, the output would be [0,1,2,6,4,5,7,8,3]


def preOrderHelper(tree, array = []):
if tree != None:
return array

In-Order Traversal

An inorder traversal…

In this article, I will demonstrate a crucial mathematical concept that is essential to constructing risk management strategies in games of chance. Using experimentation with random number generators in R, we will explore how having a fixed capital advantage over an opponent in a model investment game will yield significant probabilistic advantage towards winning in the long run.

We will compare the results of our simulations with those predicted by proven math theorems. Afterwards, we will explore the strategic implications of this concept to gambling, investing, and business.

Introduction To Risk of Ruin:

Risk of ruin is a concept commonly…


Every week, I host a poker game at my apartment. I usually have anywhere between 5 to 8 players at my table. The issue? People often decide to come, or cancel last minute and I am constantly texting people back and forth the day of the game to make sure I have a full table.

I decided to build a bot that could handle inviting my friends to my apartment, notify me of who is coming, and place extra players on waiting lists in case people cancel last minute. …

Sign up at any gym, and observe the regulars. Not the people who are in there once a week, but the regulars. Attend that gym for more than three months and you will begin to notice vastly different groups of people: those who look exactly the same, and those who have transformed. If you’re a member of the former, then this is for you.

When you ask people why they exercise, they will often give you varying answers: “to feel good”, “to sleep better” and the list goes on. But in my mind, there is only one reason to do…

In this article, I will be outlining a simple and elementary model for evaluating the overall productivity and value our lives, but before that, I will define some elementary statistics concepts.

A Quick Lesson On Statistics:

If you graduated high school, at some point you’ve come across the concept of expected value (EV). EV is the probability of an event happening multiplied by the sample size. What does this measure? In short: the payoff of an event given a specific number of trials. For example, if I roll a fair dice, wanting to land a 6, given 6 trials I…

Left Picture -> Weight: 163 lbs, BF: 17%, Waist Size (in): 33, Lean Body Mass: 135 Lbs. Right Picture -> Weight: 147 lbs, BF: 9%, Waist Size (in): 29, Lean Body Mass: 133.77

You Don’t Have To Lose All Your Muscle While Cutting:

People have the impression that you can only either bulk or cut. Either you’re losing fat at an insane rate or you’re eating everything in sight and trying to gain 10 pounds of muscle a month. Unless you’re a competitive body builder constantly preparing for competitions with super rigid deadlines, there is zero advantage in trying to expedite the process this quickly. When it comes to fitness (as a natural athlete), slow progress is the best progress. It is completely possible to see amazing strength gains while losing fat.


Pranav Ahluwalia

Computer Scientist Blog: www.pranav.ai Website: www.prandev.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store