sam.pikesley.org

Hanoi Painter

Who among us hasn't wanted to play the Towers of Hanoi on the Github commit-history graph?

Github :: Mastodon

I made some changes to my Hanoi Jane gem:

I then built Gitpaint, which allows you paint whatever 52*7, 5-grayscale data you want onto the Github graph

And then I brought it all together with this, orchestrated by Rake. The default Rake task will:

Deserialise the saved Towers

Or spawn a new set if a save-file can't be found

Render the output to Github

Which means:

  • Deleting the existing repo from Github
  • Making a new local repo
  • Making the correct commits to draw the pixels (using the Github-formatted output from Hanoi Jane)
  • Making a new Github repo
  • Pushing the local repo to Github

Sleep for 10 seconds

To allow Github time to refresh

Take a screenshot

There's some heavily cargo-culted Node which takes the screenshots using Chromium

Broadcast the screenshot

To Mastodon, using the Ternary values from Hanoi Jane as the text

Move and serialise the towers

Ready for the next run

Configuration

This all requires quite a lot of configuration, as you might expect, which should go in config/config.yaml:

Gitpaint

Needs:

  • A Github username and email, so the commits will be credited and counted correctly (I'm doing this on a separate, dedicated Github account)
  • The name of a (disposable) repo to work with: this will be created locally at /tmp/#{repo} and remotely at https://github.com/#{github_user}/#{repo} (and it will be mercilessly deleted from both places between runs)
  • A Github personal access token that has the repo privileges and, crucially, the separate delete repo privilege
  • The path to an ssh_key that can commit to the #{github_user} account
  • A scale_factor, by which each commit count will be multiplied
  • A project_url which will be added to the social media transmissions

Hanoi Jane

Needs:

  • A save_path, for saving and loading the towers between runs
  • A discs value (between 2 and 7)

Mastodon

Needs:

  • A token
  • The base_url of your Mastodon instance
  • Your account_id (which you can get by clicking on your @name from some places in the Mastodon UI)

(copy config/config-example.yaml to config/config.yaml and fill in as required)

Timescale

It takes 2187 moves to solve the 7-disc Towers of Hanoi (3**7). I've currently got this running 4 times a day, which means it will take ~546 days to finish