Created
August 25, 2014 20:43
-
-
Save ScotchyJuHotchy/68d16b0cc872435fbea0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static bool ishappy(int num) | |
| { | |
| List<int> seen = new List<int>(); | |
| seen.Add(num); | |
| List<int> multiples = new List<int>(); | |
| while (true) | |
| { | |
| int digits = numdigits(num); | |
| int moddder = 10; | |
| for (int i = 1; i <= digits; i++) | |
| { | |
| int digit = getdigit(num,i); | |
| multiples.Add(digit); | |
| } | |
| int total = 0; | |
| foreach (int m in multiples) | |
| { | |
| total += (m * m); | |
| } | |
| if (seen.Contains(total)) | |
| return false; | |
| if (total == 1) | |
| return true; | |
| seen.Add(total); | |
| num = total; | |
| multiples.Clear(); | |
| Console.WriteLine("Just calculated " + total); | |
| } | |
| } | |
| public static int getdigit(int num,int digit) | |
| { | |
| int val; | |
| int middle = num/(int)(Math.Pow(10,digit-1)); | |
| val = middle % 10; | |
| return val; | |
| } | |
| public static int numdigits(int num) | |
| { | |
| int digits = 1; | |
| if (num < 10) | |
| return digits; | |
| while (num >= 10) | |
| { | |
| digits++; | |
| num /= 10; | |
| } | |
| return digits; | |
| } | |
| static void Main(string[] args) | |
| { | |
| Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); | |
| Console.WriteLine("+ Welcome to eBay SDK for .Net Sample +"); | |
| Console.WriteLine("+ - ConsoleAddFixedPriceItem +"); | |
| Console.WriteLine("+++++++++++++++++++++++++++++++++++++++"); | |
| //[Step 1] Initialize eBay ApiContext object | |
| ApiContext apiContext = GetApiContext(); | |
| Console.WriteLine(ishappy(7)); | |
| Console.WriteLine(ishappy(2)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment