Skip to content

Instantly share code, notes, and snippets.

@karagog
karagog / palindromic_squares.go
Created June 8, 2023 15:21
This is a small program I wrote to search a dictionary for palindromic word squares of any size. See code for documentation comments.
// This program searches a dictionary for palindromic word squares, such as
// the famous SATOR square:
//
// SATOR
// AREPO
// TENET
// OPERA
// ROTAS
//
// Palindromic word squares read the same forwards, backwards and up and down.
@karagog
karagog / main.cc
Last active October 6, 2022 06:45
Chinese Rings Puzzle Solver
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// This class solves the Chinese Rings puzzle (https://en.wikipedia.org/wiki/Baguenaudier),
// optionally printing each move, and tells you how many moves it takes to solve it. It runs in O(2^N)
// time, because it actually simulates each move and it takes 2^N - 1 moves in the worst case.
class ChineseRings {
public:
@karagog
karagog / main.cpp
Last active June 18, 2022 05:31
Try-Catch-Finally in C++
#include <iostream>
#include <exception>
#include <string>
#include "trycatchfinally.h"
using namespace std;
int main()
{
// No exception
TryFinally(