## Playing: The Devil’s Calculator

A review of the game “The Devil’s Calculator.”

Cinq-Mars Media: The Devil’s Calculator

The Devil’s Calculator is a game with a simple concept. You have a calculator with unknown operators replacing the normal calculator options of plus, minus, x, and dot line dot or whatever those are. You have to play around to figure out what the mystery operators do, and then use them to get the calculator to output 666 in some way.

The game has 68 base levels (there are post-game ones, and you can create your own, too) in a few distinct phases:

1. Unary operators (or single-argument functions)
2. Binary operators (or two-argument functions)
3. Unary and binary together
4. Number sequences (or mapping functions)
5. Number sequences and one unary or binary
6. All three types together

Number sequences are patterns, such as the Fibonacci sequence, where inputting a number n refers to the nth number in that sequence.

Within each phase, the first levels are easier, and they get harder as you go, following a rollercoaster-type pattern. After each of the first segments there are short montages that show you what the new operator type is (unary, binary, and sequence).

The input of numbers and functions can be complex or simple, with recursion and order of operations coming into play.

For example, with a unary operator &, - (unary negation), and the number 3, you can do:

• &3
• &-3
• -&3
• -&-3
• Multiple uses of & on top of those above.

So, if & is f(x) = -x + 1, the outputs would be:

• -2
• 4
• 2
• -4

## Approaching the Game

Each level has two parts:

1. Figuring out the operators and sequences involved.
2. Figuring out how to use those to create the number 666.

I often found part two of the levels, getting that number out, to be harder than figuring out the level’s tools. Both parts are made harder at times by numbers and the decimal and plus/minus keys being possessed so that you cannot use them. On the other hand, that possession also gives a clue that having those keys might make things too easy.

Players should use all the tools at their disposal. The game itself includes references and links to Wolfram Alpha (Wolfram|Alpha) and the Online Encyclopedia of Integer Sequences (OEIS). I used the latter for several of the sequence levels, but instead of Wolfram Alpha I tended to use Python scripting when I needed a leg up on some of the calculating.

Players should also keep a list of their answers, including what they understood the operators and sequences to be, as some of them are reused, and even looking at what you’ve done before can help to inform your approach to the next levels.

## Difficulty

I consider it moderately difficult (I’m on level 64 after about ten hours of play), but it’s harder to handicap as the difficulty will vary by how familiar and experienced the player is with math. For students without much mathematical background, it would be more difficult, and they would be best off by tackling the levels over a longer period of time. For more experienced math persons, it would probably be a crack.

There are hints available, and you can skip levels if stuck (though the next level may also be sticky).

As I work on the final levels of the game, I’ve enjoyed my time with it. With each level beaten, there is a feeling that you are outsmarting that devil that has taken over the calculator. If you have a decent math or programming background or want to improve your math, it’s definitely worth a look.

## The Euclidean Algorithm

Implementation of the Euclidean Algorithm for finding the Greatest Common Divisor of two integers.

This post regards the Euclidean Algorithm for determining the Greatest Common Divisor (GCD) of two integers.

I happened to read about this fun and simple algorithm and decided since I’ve been doing some C programming to take a little time to implement this in C. The version below outputs to the console via printf, but could easily be modified to return a value and thus be used as part of other programs.

Here it is:

[snip out GPL notice, it's in the actual file though]
#include <stdio .h>
#include <stdlib .h>
#include <limits .h>
#include <errno .h>

int main(int argc, char **argv) {   int a,b,r; // declare variables
if (argc < 3)   {     printf("usage: gcd <value> <value> where neither == 0\n");     exit(-1);   }
b = strtol(argv[1], NULL, 10); // get values from command line   if (errno != 0 && (b == LONG_MIN || b == LONG_MAX)) // ensure valid input   {     perror("Bad argument");     exit(-1);   }
r = strtol(argv[2], NULL, 10);   if (errno != 0 && (r == LONG_MIN || r == LONG_MAX))   {     perror("Bad argument");     exit(-1);   }
if (b < r) // order them properly   {     a = r;     r = b;     b = a;   }
while (r != 0) // keep going until GCD found (worst case it's 1)   {     a = b; // shuffle values to correct spots     b = r;
if ((r = a % b) == 0) // compute the remainder, if it's 0 then GCD found     {       printf("The GCD is: %d\n", b);       exit(0);     }   }   printf("usage: gcd <value> <value> where neither == 0\n");   exit(-1); }

If I’ve made any grievous errors or there’s just a better way please let me know. This code is released under the GPL.