We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is far far more readable than prior solutions. I like it. SImilar to mine in c#
static int getTotalX(int[] a, int[] b)
{
var lcm = LCM(a);
var gcf = GCF(b);
var candidate = lcm;
var count = 0;
while (candidate<=gcf)
{
count += gcf % candidate ==0 ? 1 :0;
candidate += lcm;
}
return count;
}
static int LCM(int []x) => x.Aggregate(lCM);
static int GCF(int []x) => x.Aggregate(gCF);
static int gCF(int a, int b) => b == 0 ? a : gCF(b, a % b);
static int lCM(int a, int b) => (a *b) / gCF(a, b);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
This is far far more readable than prior solutions. I like it. SImilar to mine in c#