Happy New Year
#codingexercise
Generate the nth Newman Conway Sequence number. This sequence is shown as
1 1 2 2 3 4 4 4 5 6 7 7
It is defined as the recursion :
P(n) = P(P(n - 1)) + P(n - P(n - 1))
and with closure conditions as
P (1) = 1
P (2) = 1
double GetNCS ( double n )
{
if ( n == 1 || n == 2)
return 1;
else
return GetNCS (GetNCS (n-1)) + GetNCS (n-GetNCS (n-1));
}
n = 3:
P (P (2))+P (3-P (2))
= P (1) +P (2) = 2
n = 4
P (P (3))+P (4-P (3))
= P (2) +P (2) = 2
#codingexercise
Generate the nth Newman Conway Sequence number. This sequence is shown as
1 1 2 2 3 4 4 4 5 6 7 7
It is defined as the recursion :
P(n) = P(P(n - 1)) + P(n - P(n - 1))
and with closure conditions as
P (1) = 1
P (2) = 1
double GetNCS ( double n )
{
if ( n == 1 || n == 2)
return 1;
else
return GetNCS (GetNCS (n-1)) + GetNCS (n-GetNCS (n-1));
}
n = 3:
P (P (2))+P (3-P (2))
= P (1) +P (2) = 2
n = 4
P (P (3))+P (4-P (3))
= P (2) +P (2) = 2
No comments:
Post a Comment