Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace kontur
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- }
- public static int MinusOne => (1 << 31) >> 31;
- public static int Sum(int a, int b)
- {
- return new[] {a, b}.Sum();
- }
- public static int Sub(int a, int b)
- {
- return Sum(a, b*MinusOne);
- }
- public static int SumArray(int[] array)
- {
- try
- {
- var a = array[1];
- var length = Sub(array.Length, 1);
- return SumArray(Enumerable.Range(0, length)
- .Select(i =>
- {
- var curValue = array[i];
- var nextValue = array[Sum(i, 1)];
- var k = Sub(nextValue, curValue);
- k /= Math.Abs(k);
- return Sum(array[i], nextValue*k);
- }).ToArray());
- }
- catch (Exception)
- {
- return array[0];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment