• + 0 comments

    C# - the only problem, calculate min Multiple for 2 numbers

    private static int GCD(int a, int b)
    {
        return a == 0 ? b : GCD(b % a, a);
    }
    private static List<int> CalcNext(ref int prev, List<int> lst, int cur)
    {
        int gcd = GCD(prev,cur);
        lst.Add((prev/gcd)*(cur/gcd)*gcd);
        prev = cur;
        return lst;
    }
    public static List<int> solve(List<int> a)
    {
        int prev = a.ElementAt(0), prevB = prev;
        List<int> ret = a.Skip(1).Aggregate(new List<int>{prev}, (lst,cur)=>CalcNext(ref prev, lst, cur)).ToList();
        ret.Add(a.Last());
        return ret;
    }
    

    ...not the shortest code though