Skip to content

Commit

Permalink
Create 6 kyu - Compile time #2 Ackermann function.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
freedan42x authored Jul 18, 2022
1 parent 0ea882b commit 1a0592f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cpp/6 kyu - Compile time #2 Ackermann function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
typedef unsigned long long ull_t;

template <int m, int n>
struct ackermann
{
enum : ull_t { value = ackermann<m - 1, ackermann<m, n - 1>::value>::value };
};

template <>
struct ackermann<0, 0>
{
enum : ull_t { value = 1 };
};

template <int n>
struct ackermann<0, n>
{
enum : ull_t { value = n + 1 };
};

template <int m>
struct ackermann<m, 0>
{
enum : ull_t { value = ackermann<m - 1, 1>::value };
};

0 comments on commit 1a0592f

Please sign in to comment.