Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ASD
- {
- class Program
- {
- static int GCD(int a, int b)
- {
- while (b != 0)
- {
- int t = b;
- b = a % b;
- a = t;
- }
- return a;
- }
- static int GCDR(int a, int b)
- {
- if (b == 0)
- {
- return a;
- }
- return GCDR(b, a % b);
- }
- static int GCD3(int a, int b, int c)
- {
- return GCD(GCD(a, b), c);
- }
- static int GCDN(params int[] nums)
- {
- int result = nums[0];
- for (int i = 1; i < nums.Length; i++)
- {
- result = GCD(result, nums[i]);
- }
- return result;
- }
- static int DigitSumI(int num)
- {
- int sum = 0;
- while (num != 0)
- {
- sum += num % 10;
- num /= 10;
- }
- return sum;
- }
- static int DigitSum(int num)
- {
- if (num < 10)
- {
- return num;
- }
- return num % 10 + DigitSum(num / 10);
- }
- static int DigitRoot(int num)
- {
- if (num < 10)
- {
- return num;
- }
- return DigitRoot(DigitSum(num));
- }
- static int count = 0;
- static int ArrayWalk(int[] arr, int index)
- {
- if (index < 0 || index >= arr.Length || arr[index] == -1)
- {
- Console.WriteLine("out");
- return 0;
- }
- Console.Write(arr[index] + "->");
- if (DigitSum(arr[index]) % 2 == 0)
- {
- arr[index] = -1;
- return 1 + ArrayWalk(arr, index + 3);
- }
- else
- {
- arr[index] = -1;
- return 1 + ArrayWalk(arr, index - 2);
- }
- }
- static int EvenCount(int[] arr, int index)
- {
- if (index >= arr.Length)
- {
- return 0;
- }
- if (arr[index] % 2 == 0)
- {
- return 1 + EvenCount(arr, index + 1);
- }
- else
- {
- return EvenCount(arr, index + 1);
- }
- }
- static bool EGNCheck(string egn)
- {
- if (egn.Length != 10)
- {
- return false;
- }
- int[] coeff = { 2, 4, 8, 5, 10, 9, 7, 3, 6 };
- int digit = 0;
- for (int i = 0; i < 9; i++)
- {
- digit += (egn[i] - '0') * coeff[i];
- }
- digit %= 11;
- if (digit == 10)
- {
- digit = 0;
- }
- if (digit == (egn[9] - '0'))
- {
- return true;
- }
- return false;
- }
- static void Main(string[] args)
- {
- Console.WriteLine(EGNCheck("6101057509"));
- /*int[] arr = { 5, 23, 77, 123, 681, 9, 772, 16 };
- Console.WriteLine("Even count: " + EvenCount(arr, 0));
- /*int steps = ArrayWalk(arr, 4);
- Console.WriteLine(steps);*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement