# Compare array of decimal sum of Integers and exact fractional part

Develop a program which takes two arrays of decimal numbers, and compare the sum of whole numbers only and the decimal part. If the sums of the whole numbers are the same, and the decimal parts of Array a are a subset of the decimal parts of Array b, return True. Otherwise, return False.

Example-1 :-

Array a ={2.5,3.0,1.3}

Array b = {5.0,1.0,0.5,0.3}

Sum of whole numbers: Array a = 2+3+1 = 6 and Array b = 5+1 =6 --Matched

Individual fraction part: Array a = 2.5 = 0.5 and Array b = 0.5--Matched

Individual fraction part: Array a = 1.3 = 0.3 and Array b = 0.3--Matched

All the above are matched, so it returns true.

Example-2 :-

Array a ={1.7,2.3}

Array b = {1.2,0.5,2.3}

Sum of the whole numbers: Array a = 2+1 = 3 and Array b = 2+1 =3 --Matched

Individual fraction part: Array a = 1.7 = 0.7 and Array b = 0.2 or .5 or .3 --No Exact match

Individual fraction part: Array a = 2.3 = 0.3 and Array b = 2.3 = 0.3 -Matched

One of the conditions is not matched, so it returns false.

• What is the winning criterion? Is it code golf? Apr 6 '15 at 14:56
• Yes its code-golf forgot to add it Apr 6 '15 at 15:10
• Well, add the code-golf tag then. Apr 6 '15 at 15:12
• I'm a little confused, can you clarify what you mean? Apr 6 '15 at 15:30
• @ASCIIThenANSI sum(floor(a))==sum(floor(b)) and filter_nonzeros(fraction_part(a))==some_permutation(filter_nonzeros(fraction_part(b))) has to be true if I'm correct. @andyra42 Is this correct? Apr 6 '15 at 15:40

# Mathematica 88 81

This should be easy to beat. I was surprised that Rationalize was needed.

r=Rationalize;f=Floor;
(Tr[f@#]==Tr[f@#2] && Complement[r@Mod[#2,1],r@Mod[#, 1]]=={})&


(Tr[f@#]==Tr[f@#2] && Complement[r@Mod[#2,1],r@Mod[#, 1]]=={})&
@@ {{2.5, 3.0, 1.3}, {5.0, 1.0,0.5, 0.3}}


True

(Tr[f@#]==Tr[f@#2] && Complement[r@Mod[#2,1],r@Mod[#, 1]]=={})& @@
{{1.7, 2.3}, {1.2, 0.5, 2.3}}


False

• You can shorten the FractionalPart by using Mod[n,1]. Apr 6 '15 at 16:42
• @LegionMammal978 You're right! Thanks. Apr 6 '15 at 17:05
• I think you can save some bytes with Infix and Prefix syntax: (Tr@f@#==Tr@f@#2&&r@Mod[#2,1]~Complement~r@Mod[#,1]=={})& Jul 18 '17 at 9:46