PloadyFree

Kontur Code Retreat

Jan 11th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace kontur
  5. {
  6.     public class Program
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.  
  11.         }
  12.  
  13.         public static int MinusOne => (1 << 31) >> 31;
  14.  
  15.         public static int Sum(int a, int b)
  16.         {
  17.             return new[] {a, b}.Sum();
  18.         }
  19.  
  20.         public static int Sub(int a, int b)
  21.         {
  22.             return Sum(a, b*MinusOne);
  23.         }
  24.  
  25.         public static int SumArray(int[] array)
  26.         {
  27.             try
  28.             {
  29.                 var a = array[1];
  30.  
  31.                 var length = Sub(array.Length, 1);
  32.                 return SumArray(Enumerable.Range(0, length)
  33.                     .Select(i =>
  34.                     {
  35.                         var curValue = array[i];
  36.                         var nextValue = array[Sum(i, 1)];
  37.  
  38.                         var k = Sub(nextValue, curValue);
  39.                         k /= Math.Abs(k);
  40.  
  41.                         return Sum(array[i], nextValue*k);
  42.                     }).ToArray());
  43.             }
  44.             catch (Exception)
  45.             {
  46.                 return array[0];
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment