— CAN YOU SOLVE THIS - EXCEL CHALLENGE 186 —
(Solutions in any language are also welcome for Excel Challenges)
If odd numbers are less, then post odd numbers.
If even numbers are less, then post even numbers.
If both are equal, answer would be none.
Ex. 3, 8, 9, 4, 6 => It contains 2 odd numbers 3, 9 and 3 even numbers 8, 4, 6. Hence, answer would be 3, 9.
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/djqQHBvf
#excel, #excelchallenge, #powerquerychallenge, #daxchallenge, #m, #dax, #powerbi, #powerquery, #powerpivot, #sheets, #googlesheets, #data, #analytics, #businessintelligence, #finance, #office365, #python, #r
Excel BI LinkedIn Post
=MAP(A2:A7,LAMBDA(a,LET(n,TEXTSPLIT(a,", "),z,MOD(n,2),s,2*SUM(z),c,COUNT(z),TEXTJOIN(", ",,IF(s=c,"",IFERROR(FILTER(n,z=(1-(s>c))),""))))))
NOTE: This formula is 27 characters shorter than my first one; however, for the first time in a LONG time, my formula is even shorter (by 10 characters) than Bo Rydobon’s formula! I’m betting that should spur Bo Rydobon to create an even shorter formula now.
Hi to all!
One option could be:
=MAP(A2:A7,LAMBDA(x,LET(n,TEXTSPLIT(x,", "),m,MOD(n,2),TEXTJOIN(", ",,IF(CHOOSE(2+SIGN(SUM(1-m)-SUM(m)),1-m,,m),n,"")))))
Blessings!
Odd and Even Numbers w/ #powerquery. #bitanbit #powerbi
let
Source = Excel.CurrentWorkbook(){[Name="Input"]}[Content],
Solution = Table.TransformRows(Source, each
let
n = Text.Split([Numbers], ", "),
o = [List.Select](http://list.select/)(n, each Number.IsOdd(Number.From(_))),
oc = List.Count(o),
e = List.Difference(n, o),
ec = List.Count(e)
in
Text.Combine(if ec < oc then e else if oc < ec then o else {}, ", "))
in
Solution
Hi all, I am loving these challenges! Here is my answer:
=MAP(A2:A7,LAMBDA(_a,LET(a,TEXTSPLIT(_a,", "),
_even,SUM(--ISEVEN(a)),
_odd,SUM(--ISODD(a)),
ARRAYTOTEXT(IFERROR(IF(_even<_odd,FILTER(a,ISEVEN(a)=TRUE),IF(_odd<_even,FILTER(a,ISODD(a)=TRUE),"")),"")))))