--- CAN YOU SOLVE THIS - EXCEL CHALLENGE 334 --- -Daily Challenges @ 4am UTC | Excel: Mon to Fri | Power Query: Sat & Sun- (Solutions in any language are also welcome for Excel Challenges) List the Amicable numbers. A pair of numbers N1 and N2 is called Amicable if the sum of the proper divisors of either one is equal to the other. Ex. 220 and 284 Proper divisors of 220 - 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110 -> The sum of proper divisors is 284. Proper divisors of 284 - 1, 2, 4, 71 and 142 -> The sum of proper divisors is 220. Post answers in Comment. (Your formula need not be a single formula. You can write multiple formulas to arrive at a solution. Also your formula need not be different from others as long as you have worked out your formula independently) Download Practice File - https://lnkd.in/dVENHNKM #excel, #excelchallenge, #powerquerychallenge, #daxchallenge, #m, #dax, #powerbi, #powerquery, #powerpivot, #sheets, #googlesheets, #data, #analytics, #businessintelligence, #finance, #office365, #python, #r
Hi Friends... Here's my {M} Code: let Source = Excel.CurrentWorkbook(){0}[Content], Anw = Table.SelectRows(Source, each let N1 = [Number 1], N2 = [Number 2], AN = let LN1 = {1..N1}, LN2 = {1..N2}, Fn_SPN = (L1 as list, n as number) => let a = List.Transform(L1, each n/_), b = List.Select(a, each Number.Mod(_,1) = 0), x = List.Sum(List.RemoveFirstN(b)) in x, Check = Fn_SPN(LN1, N1) = N2 and Fn_SPN(LN2, N2) = N1 in Check in AN) in Anw 🧙♂️🧙♂️🧙♂️
=LET(a,A2:A10,b,B2:B10,x,LAMBDA(a,LET(s,SEQUENCE(a^0.5,,2),SUM(1,IF(MOD(a,s),,s+a/s)))),FILTER(A2:B10,(MAP(a,x)=b)*(MAP(b,x)=a)))
I did this using 4 columns. Columns 1 and 2 to determine whether the one number is Amicable of the other --(SUM(LET(x,A2,y,SEQUENCE(INT(ROUNDDOWN(x/2,0)),,1,1),IF(MOD(x,y)=0,y,0)))=B2). Columns 3 and 4 to filter the numbers if Columns 1 and 2 equal 1. I'm sure you can do it in 2 columns and certain it can be done in 1.
Amicable Numbers w/ #powerquery . #bitanbit #powerbi let Source = Excel.CurrentWorkbook(){[Name = "Input"]}[Content], I = Int64.From, L = each List.Sum(List.Select({1 .. I(_ / 2)}, (s) => let d = _ / s in d = I(d))), S = Table.SelectRows(Source, each L([Number 1]) = [Number 2] and [Number 1] = L([Number 2])) in S
Adjunto mi query... let Source = Excel.CurrentWorkbook(){0}[Content], Fx = (f)=> let a = {2..Number.RoundDown(Number.Sqrt(f))}, b = List.Sum(List.Combine(List.Transform(List.Select(a, each Number.Mod(f, _)=0), each {_} & {f/_})))+1 in b, Sol = Table.SelectRows(Source, each Fx([Number 1])=[Number 2] and Fx([Number 2])=[Number 1]) in Sol
My M-Code let Origen = Excel.CurrentWorkbook(){[Name="Tabla1"]}[Content], Fx = (x)=> let a = x, b = {1..Number.RoundDown(a/2)}, c = List.Transform(b, each a/_), d = List.Zip({b,c}), e = List.Select(d, each Number.Mod(_{1},1)=0), f = List.Sum(List.Transform(e, each _{0})) in f, g = Table.AddColumn(Origen, "N1", each Fx([Number 1])), h = Table.AddColumn(g, "N2", each Fx([Number 2])), Sol = Table.SelectRows(h, each [Number 1]=[N2] and [Number 2]=[N1])[[Number 1],[Number 2]] in Sol
☑=FILTER(A2:B10,MAP(A2:A10,B2:B10,LAMBDA(x,y,LET(a,x,b,y,c,SEQUENCE(a/2),d,SEQUENCE(b/2),SUM(FILTER(c,MOD(a,c)=0),a)=SUM(FILTER(d,MOD(b,d)=0),b)))))
Somehow this works. =LET(array,IFERROR(SORT(HSTACK(MAP(A2:A10,B2:B10, LAMBDA(a,b, IF(SUM(LET(x,SEQUENCE(ROUND(a/2,0),2),IF(MOD(a,x)=0,x,"")))=SUM(LET(x,SEQUENCE(ROUND(b/2,0),2),IF(MOD(b,x)=0,x,""))),TEXTJOIN(",",TRUE,a),""))), MAP(A2:A10,B2:B10, LAMBDA(a,b, IF(SUM(LET(x,SEQUENCE(ROUND(a/2,0),2),IF(MOD(a,x)=0,x,"")))=SUM(LET(x,SEQUENCE(ROUND(b/2,0),2),IF(MOD(b,x)=0,x,""))),TEXTJOIN(",",TRUE,b),""))))*1,,1),0), FILTER(array,CHOOSECOLS(array,1)>0))
let Fonte = Tabela1, res = Table.SelectRows(Fonte, each [ a = List.Sum(List.Select(List.Transform({1..[Number 1]}, (x)=> [Number 1]/x ),each _ = Int64.From(_))), b = List.Sum(List.Select(List.Transform({1..[Number 2]}, (x)=> [Number 2]/x ),each _ = Int64.From(_))), c = a = b ][c]) in res
List of all Challenges posted so far with Challenge Links and Practice File Links https://1drv.ms/x/s!Akd5y6ruJhvhvjsDKLMvtQ7RVuqW?e=NWYAvM All Challenge files in one place - https://drive.google.com/drive/folders/1WqImwmvZfVT0RG4oja_tdi7wTWk3etY6?usp=sharing