-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlynNumberChallenge.cs
More file actions
49 lines (40 loc) · 1.08 KB
/
FlynNumberChallenge.cs
File metadata and controls
49 lines (40 loc) · 1.08 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// https://www.sololearn.com/Discuss/626739/?ref=app
namespace SoloLearn
{
class Program
{
static void Main(string[] zephyr_koo)
{
var input = Console.ReadLine();
int number;
if (Int32.TryParse(input, out number))
{
Console.WriteLine($"{ GetNthFlynNumber(number) } is the no. { number } flyn number. ^_^");
}
}
static int GetNthFlynNumber(int nth)
{
int count = 0, num = 0;
while (count != nth)
{
num++;
if (IsFlynNumber(num))
count++;
}
return num;
}
static bool IsFlynNumber(int num)
{
return GetDigitSum(num) == GetDigitSum(num * num / 3);
}
static double GetDigitSum(int num)
{
return num.ToString().Sum(d => char.GetNumericValue(d));
}
}
}