No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a riddle answer simulator, written in Ruby, to test answers to the following riddle:

  • 100 clowns in a line, all wearing a red or blue balloon hat
  • a clown does not know which color hat they are wearing
  • all clowns face the same direction, so that first clown can see all 99 clowns and their hat colors ahead of them
  • clown cannot see hats / colors behind them
  • starting at first clown, they can ONLY say either "red" or "blue" (cannot pass information any other way). If the answer does not match their hat color, balloon gets popped.

What is the optimal strategy the clowns should use to ensure the most amount of clowns don't get their balloon hats popped?

To run the simulation, type the following into your console:

ruby perform_hat_ritual.rb 20

In the last number is an argument to the ruby script, which specifies the number of times to run the simulation.


If you don't have Ruby setup locally, you can do one of two things:

  1. Install docker, and follow golubitsky's awesome posts on how to setup a dockerized Rails environment on Windows here and here

  2. Do the below steps to install ruby on your computer.

First, make sure you have ruby installed by typing the following into your console:

ruby -v

If you don't have ruby installed, or your ruby version is less than 1.9, install the latest version of Ruby from

Now, install ruby gems (the ability to download ruby 'gems' or libraries, from the command line) by cloning ruby gems from github and running the setup file. ###Note: you'll have to make sure your powershell session is being run as administrator

cd some_directory_you_put_repos_you_clone
git clone
cd rubygems
ruby setup.rb

Now that you can easily install gems, you'll want to install a useful gem called bundler, which is a sort of package manager for ruby gems:

cd ..
gem install bundler

Now clone my repo, and use bundler to install the gems required for debugging:

git clone
cd blue_hat_red_hat
bundle install

You should now be good to go.

Note on debugging:

This repo uses a gem called pry-byebug (which is specified in the repo's Gemfile, which bundler uses to identify which gems it should install) as a default debugger.

If you want to put a break point in the code, insert binding.pry at your desired breakpoint, and save. As an example, the main branch has binding.pry already in the execution script, so if everything is setup correctly, the first time you run ruby perform_hat_ritual.rb 20 , you will hit a breakpoint.

This will be the hook that allows you to go line by line, step into functions, or continue. To exit the debug session, you can type !!!. More info on pry-byebug's debug commands here: