C
c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Author: Xan
* Date: 25th April 2018.
*
* Calculate how many moves can be made by a knight
* from the square specified.
*/
#include <stdio.h>
#include <math.h>
/**
* I initially used knight_function() which was my intuitive meandering to
* find a formula for the solution. I later sat down and improve on this,
* see knight_function2(). I always knew the formula for a circle,
* r^2 = x^2 + y^2 involved in the solution which is where the
* sqrt( x * x + y * y) comes in (this is the radius of the number
* circles). If you look at the solution, there are circles of 2, 3, 4
* and 6, although the circumference of the 2 and 3 numbered circles only
* just touch the corners.
* These gave me a headache for quite a few days, I even left some weird
* mathematical sketchings on a blackboard I discovered in a public
* building!
*/
/**
* Calculate how many moves can be made by the knight
* from the square specified.
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run