[{"data":1,"prerenderedAt":3707,"buildId":3708},["ShallowReactive",2],{"\u002Fprojects\u002Ffind-addends-1":3},{"id":4,"title":5,"body":6,"createdAt":3697,"description":3698,"extension":3699,"meta":3700,"navigation":3701,"path":3702,"seo":3703,"stem":3704,"subtitle":3705,"__hash__":3706},"content\u002Fprojects\u002Ffind-addends-1.md","find_addends - Part 1",{"type":7,"value":8,"toc":3694},"minimark",[9,14,18,35,40,49,52,56,64,86,101,122,437,898,1148,1152,1191,1208,1216,1262,1272,1299,1309,1318,1339,1369,1389,1399,1413,1422,1649,1655,1993,2103,2124,2128,2143,2157,2180,2202,2222,2257,2299,2305,2309,2321,2336,2339,2349,2352,2361,2976,2979,3604,3666,3676],[10,11],"r-post-img",{"alt":12,"src":13},"A preliminary graph of estimated performance.","https:\u002F\u002Flive.staticflickr.com\u002F65535\u002F51155905152_4d30e1edb0_o.png",[15,16,17],"p",{},"This series of posts outlines one of my more technical projects to date. I attempt to\nsolve a puzzle using two approaches. My goal is to optimize my custom\napproach until it can consistently outperform the more traditional approach\non a variety of data sets. I anticipate this will require a rather long explanation\nso this project will come in parts.",[15,19,20,21,28,29,34],{},"Beyond simply improving my own algorithm\nI also plan to benchmark the varying results, perform noise reduction on the benchmarks,\nand compile for multiple targets including ",[22,23,27],"a",{"href":24,"rel":25},"https:\u002F\u002Fwebassembly.org\u002F",[26],"nofollow","Web Assembly",". All\nsource code for this project is available on\n",[22,30,33],{"href":31,"rel":32},"https:\u002F\u002Fgithub.com\u002Fanthonyarusso\u002Ffind-addends",[26],"Github",".",[36,37,39],"h5",{"id":38},"background","Background",[15,41,42,43,48],{},"As I worked through the ",[22,44,47],{"href":45,"rel":46},"https:\u002F\u002Fadventofcode.com\u002F2020\u002Fday\u002F1",[26],"Advent of Code 2020 day 1","\npuzzle it occurred to me there was a considerably faster approach to computing the solution.\nThe puzzle itself is rather straightforward. You are given a list of numbers and are asked\nto find the two numbers in the list which sum to 2020. Afterwards you are asked to repeat\nthis process but to instead find three addends summing to 2020.",[15,50,51],{},"The most straightforward solution is to find all combinations with two selections of the\nlisted numbers, add them, and see if the result is 2020. Then repeat this process for\nall three-selection combinations.",[36,53,55],{"id":54},"developing-a-new-approach","Developing a New Approach",[15,57,58,59,63],{},"I realized it made no sense to try adding numbers that were\nboth less than half of the desired sum. ",[60,61,62],"strong",{},"Two numbers both less than or both greater than\nhalf the desired number could never sum to the desired number."," This is the basis of\nmy approach.",[15,65,66,69,70,74,75,78,79,82,83,34],{},[60,67,68],{},"Terminology:"," Going forward I will refer to addends less than half the desired sum as\n",[71,72,73],"code",{},"smalls"," and addends greater than half the desired sum as ",[71,76,77],{},"bigs",". The \"straightforward\"\nsolution I referred to previously will be called ",[71,80,81],{},"use_combos"," and my own custom algorithm\nwill be called ",[71,84,85],{},"find_addends",[15,87,88,89,92,93,96,97,100],{},"The ",[71,90,91],{},"small"," and ",[71,94,95],{},"big"," values from our initial list will be sorted into their own respective\nlists by comparing each entry to half the sum. Now only combinations of ",[71,98,99],{},"small + big"," need\nto be considered.",[15,102,103,104,106,107,109,110,112,113,115,116,118,119,121],{},"In the worst case scenario for ",[71,105,85],{}," there are an equal number of ",[71,108,77],{}," and\n",[71,111,73],{}," meaning we may have to compare each ",[71,114,91],{}," to every ",[71,117,95],{}," until we find\na solution. Compare this to ",[71,120,81],{},"'s worst case where every entry must be\ncompared against every other entry.",[15,123,124,125,129,130,319,320,92,322,434,435,34],{},"Where ",[126,127,128],"em",{},"n"," is the number of entries in the list we expect something like\n",[131,132,135,177],"span",{"className":133},[134],"katex",[131,136,139],{"className":137},[138],"katex-mathml",[140,141,143],"math",{"xmlns":142},"http:\u002F\u002Fwww.w3.org\u002F1998\u002FMath\u002FMathML",[144,145,146,172],"semantics",{},[147,148,149,154,164],"mrow",{},[150,151,153],"mo",{"stretchy":152},"false","(",[155,156,157,160],"mfrac",{},[158,159,128],"mi",{},[161,162,163],"mn",{},"2",[165,166,167,170],"msup",{},[150,168,169],{"stretchy":152},")",[161,171,163],{},[173,174,176],"annotation",{"encoding":175},"application\u002Fx-tex","(\\frac{n}{2})^2",[131,178,182],{"className":179,"ariaHidden":181},[180],"katex-html","true",[131,183,186,191,195,286],{"className":184},[185],"katex-base",[131,187],{"className":188,"style":190},[189],"katex-strut","height:1.1591em;vertical-align:-0.345em;",[131,192,153],{"className":193},[194],"mopen",[131,196,199,203,282],{"className":197},[198],"mord",[131,200],{"className":201},[194,202],"nulldelimiter",[131,204,206],{"className":205},[155],[131,207,211,273],{"className":208},[209,210],"vlist-t","vlist-t2",[131,212,215,268],{"className":213},[214],"vlist-r",[131,216,220,241,252],{"className":217,"style":219},[218],"vlist","height:0.6954em;",[131,221,223,228],{"style":222},"top:-2.655em;",[131,224],{"className":225,"style":227},[226],"pstrut","height:3em;",[131,229,235],{"className":230},[231,232,233,234],"katex-sizing","reset-size6","size3","mtight",[131,236,238],{"className":237},[198,234],[131,239,163],{"className":240},[198,234],[131,242,244,247],{"style":243},"top:-3.23em;",[131,245],{"className":246,"style":227},[226],[131,248],{"className":249,"style":251},[250],"frac-line","border-bottom-width:0.04em;",[131,253,255,258],{"style":254},"top:-3.394em;",[131,256],{"className":257,"style":227},[226],[131,259,261],{"className":260},[231,232,233,234],[131,262,264],{"className":263},[198,234],[131,265,128],{"className":266},[198,267,234],"mathnormal",[131,269,272],{"className":270},[271],"vlist-s","​",[131,274,276],{"className":275},[214],[131,277,280],{"className":278,"style":279},[218],"height:0.345em;",[131,281],{},[131,283],{"className":284},[285,202],"mclose",[131,287,289,292],{"className":288},[285],[131,290,169],{"className":291},[285],[131,293,296],{"className":294},[295],"msupsub",[131,297,299],{"className":298},[209],[131,300,302],{"className":301},[214],[131,303,306],{"className":304,"style":305},[218],"height:0.8141em;",[131,307,309,313],{"style":308},"top:-3.063em;margin-right:0.05em;",[131,310],{"className":311,"style":312},[226],"height:2.7em;",[131,314,316],{"className":315},[231,232,233,234],[131,317,163],{"className":318},[198,234]," iterations for ",[71,321,85],{},[131,323,325,348],{"className":324},[134],[131,326,328],{"className":327},[138],[140,329,330],{"xmlns":142},[144,331,332,345],{},[147,333,334,336,343],{},[150,335,153],{"fence":181},[155,337,339,341],{"linethickness":338},"0px",[158,340,128],{},[161,342,163],{},[150,344,169],{"fence":181},[173,346,347],{"encoding":175},"{n\\choose 2}",[131,349,351],{"className":350,"ariaHidden":181},[180],[131,352,354,358],{"className":353},[185],[131,355],{"className":356,"style":357},[189],"height:1.2em;vertical-align:-0.35em;",[131,359,361],{"className":360},[198],[131,362,364,374,428],{"className":363},[198],[131,365,369],{"className":366,"style":368},[194,367],"delimcenter","top:0em;",[131,370,153],{"className":371},[372,373],"delimsizing","size1",[131,375,377],{"className":376},[155],[131,378,380,420],{"className":379},[209,210],[131,381,383,417],{"className":382},[214],[131,384,387,402],{"className":385,"style":386},[218],"height:0.7454em;",[131,388,390,393],{"style":389},"top:-2.355em;",[131,391],{"className":392,"style":312},[226],[131,394,396],{"className":395},[231,232,233,234],[131,397,399],{"className":398},[198,234],[131,400,163],{"className":401},[198,234],[131,403,405,408],{"style":404},"top:-3.144em;",[131,406],{"className":407,"style":312},[226],[131,409,411],{"className":410},[231,232,233,234],[131,412,414],{"className":413},[198,234],[131,415,128],{"className":416},[198,267,234],[131,418,272],{"className":419},[271],[131,421,423],{"className":422},[214],[131,424,426],{"className":425,"style":279},[218],[131,427],{},[131,429,431],{"className":430,"style":368},[285,367],[131,432,169],{"className":433},[372,373]," iterations for\n",[71,436,81],{},[15,438,439,440,109,442,92,444,446,447,546,547,644,645,647,648,644,745,747,748,885,886,888,889,894,895,897],{},"In further detail, if there are an equal number of ",[71,441,77],{},[71,443,73],{},[126,445,128],{}," entries in total then we know there are ",[131,448,450,468],{"className":449},[134],[131,451,453],{"className":452},[138],[140,454,455],{"xmlns":142},[144,456,457,465],{},[147,458,459],{},[155,460,461,463],{},[158,462,128],{},[161,464,163],{},[173,466,467],{"encoding":175},"\\frac{n}{2}",[131,469,471],{"className":470,"ariaHidden":181},[180],[131,472,474,478],{"className":473},[185],[131,475],{"className":476,"style":477},[189],"height:1.0404em;vertical-align:-0.345em;",[131,479,481,484,543],{"className":480},[198],[131,482],{"className":483},[194,202],[131,485,487],{"className":486},[155],[131,488,490,535],{"className":489},[209,210],[131,491,493,532],{"className":492},[214],[131,494,496,510,518],{"className":495,"style":219},[218],[131,497,498,501],{"style":222},[131,499],{"className":500,"style":227},[226],[131,502,504],{"className":503},[231,232,233,234],[131,505,507],{"className":506},[198,234],[131,508,163],{"className":509},[198,234],[131,511,512,515],{"style":243},[131,513],{"className":514,"style":227},[226],[131,516],{"className":517,"style":251},[250],[131,519,520,523],{"style":254},[131,521],{"className":522,"style":227},[226],[131,524,526],{"className":525},[231,232,233,234],[131,527,529],{"className":528},[198,234],[131,530,128],{"className":531},[198,267,234],[131,533,272],{"className":534},[271],[131,536,538],{"className":537},[214],[131,539,541],{"className":540,"style":279},[218],[131,542],{},[131,544],{"className":545},[285,202]," addends of\neither type. Worst case, we compare ",[131,548,550,567],{"className":549},[134],[131,551,553],{"className":552},[138],[140,554,555],{"xmlns":142},[144,556,557,565],{},[147,558,559],{},[155,560,561,563],{},[158,562,128],{},[161,564,163],{},[173,566,467],{"encoding":175},[131,568,570],{"className":569,"ariaHidden":181},[180],[131,571,573,576],{"className":572},[185],[131,574],{"className":575,"style":477},[189],[131,577,579,582,641],{"className":578},[198],[131,580],{"className":581},[194,202],[131,583,585],{"className":584},[155],[131,586,588,633],{"className":587},[209,210],[131,589,591,630],{"className":590},[214],[131,592,594,608,616],{"className":593,"style":219},[218],[131,595,596,599],{"style":222},[131,597],{"className":598,"style":227},[226],[131,600,602],{"className":601},[231,232,233,234],[131,603,605],{"className":604},[198,234],[131,606,163],{"className":607},[198,234],[131,609,610,613],{"style":243},[131,611],{"className":612,"style":227},[226],[131,614],{"className":615,"style":251},[250],[131,617,618,621],{"style":254},[131,619],{"className":620,"style":227},[226],[131,622,624],{"className":623},[231,232,233,234],[131,625,627],{"className":626},[198,234],[131,628,128],{"className":629},[198,267,234],[131,631,272],{"className":632},[271],[131,634,636],{"className":635},[214],[131,637,639],{"className":638,"style":279},[218],[131,640],{},[131,642],{"className":643},[285,202]," ",[71,646,73],{}," to ",[131,649,651,668],{"className":650},[134],[131,652,654],{"className":653},[138],[140,655,656],{"xmlns":142},[144,657,658,666],{},[147,659,660],{},[155,661,662,664],{},[158,663,128],{},[161,665,163],{},[173,667,467],{"encoding":175},[131,669,671],{"className":670,"ariaHidden":181},[180],[131,672,674,677],{"className":673},[185],[131,675],{"className":676,"style":477},[189],[131,678,680,683,742],{"className":679},[198],[131,681],{"className":682},[194,202],[131,684,686],{"className":685},[155],[131,687,689,734],{"className":688},[209,210],[131,690,692,731],{"className":691},[214],[131,693,695,709,717],{"className":694,"style":219},[218],[131,696,697,700],{"style":222},[131,698],{"className":699,"style":227},[226],[131,701,703],{"className":702},[231,232,233,234],[131,704,706],{"className":705},[198,234],[131,707,163],{"className":708},[198,234],[131,710,711,714],{"style":243},[131,712],{"className":713,"style":227},[226],[131,715],{"className":716,"style":251},[250],[131,718,719,722],{"style":254},[131,720],{"className":721,"style":227},[226],[131,723,725],{"className":724},[231,232,233,234],[131,726,728],{"className":727},[198,234],[131,729,128],{"className":730},[198,267,234],[131,732,272],{"className":733},[271],[131,735,737],{"className":736},[214],[131,738,740],{"className":739,"style":279},[218],[131,741],{},[131,743],{"className":744},[285,202],[71,746,77],{}," thus\nwe expect ",[131,749,751,776],{"className":750},[134],[131,752,754],{"className":753},[138],[140,755,756],{"xmlns":142},[144,757,758,774],{},[147,759,760,762,768],{},[150,761,153],{"stretchy":152},[155,763,764,766],{},[158,765,128],{},[161,767,163],{},[165,769,770,772],{},[150,771,169],{"stretchy":152},[161,773,163],{},[173,775,176],{"encoding":175},[131,777,779],{"className":778,"ariaHidden":181},[180],[131,780,782,785,788,856],{"className":781},[185],[131,783],{"className":784,"style":190},[189],[131,786,153],{"className":787},[194],[131,789,791,794,853],{"className":790},[198],[131,792],{"className":793},[194,202],[131,795,797],{"className":796},[155],[131,798,800,845],{"className":799},[209,210],[131,801,803,842],{"className":802},[214],[131,804,806,820,828],{"className":805,"style":219},[218],[131,807,808,811],{"style":222},[131,809],{"className":810,"style":227},[226],[131,812,814],{"className":813},[231,232,233,234],[131,815,817],{"className":816},[198,234],[131,818,163],{"className":819},[198,234],[131,821,822,825],{"style":243},[131,823],{"className":824,"style":227},[226],[131,826],{"className":827,"style":251},[250],[131,829,830,833],{"style":254},[131,831],{"className":832,"style":227},[226],[131,834,836],{"className":835},[231,232,233,234],[131,837,839],{"className":838},[198,234],[131,840,128],{"className":841},[198,267,234],[131,843,272],{"className":844},[271],[131,846,848],{"className":847},[214],[131,849,851],{"className":850,"style":279},[218],[131,852],{},[131,854],{"className":855},[285,202],[131,857,859,862],{"className":858},[285],[131,860,169],{"className":861},[285],[131,863,865],{"className":864},[295],[131,866,868],{"className":867},[209],[131,869,871],{"className":870},[214],[131,872,874],{"className":873,"style":305},[218],[131,875,876,879],{"style":308},[131,877],{"className":878,"style":312},[226],[131,880,882],{"className":881},[231,232,233,234],[131,883,163],{"className":884},[198,234]," iterations. For ",[71,887,81],{}," we simply\nexpect the number of\n",[22,890,893],{"href":891,"rel":892},"https:\u002F\u002Fbetterexplained.com\u002Farticles\u002Feasy-permutations-and-combinations\u002F",[26],"two-selection combinations","\nof ",[126,896,128],{}," entries.",[15,899,900,901,1008,1009,1147],{},"So far, so good. In theory we should be down from\n",[22,902,905],{"href":903,"rel":904},"https:\u002F\u002Fmath.stackexchange.com\u002Fquestions\u002F1265519\u002Fapproximation-of-combination-n-choose-k-theta-left-nk-right",[26],[131,906,908,930],{"className":907},[134],[131,909,911],{"className":910},[138],[140,912,913],{"xmlns":142},[144,914,915,927],{},[147,916,917,919,925],{},[150,918,153],{"fence":181},[155,920,921,923],{"linethickness":338},[158,922,128],{},[161,924,163],{},[150,926,169],{"fence":181},[173,928,929],{"encoding":175},"{n \\choose 2}",[131,931,933],{"className":932,"ariaHidden":181},[180],[131,934,936,939],{"className":935},[185],[131,937],{"className":938,"style":357},[189],[131,940,942],{"className":941},[198],[131,943,945,951,1002],{"className":944},[198],[131,946,948],{"className":947,"style":368},[194,367],[131,949,153],{"className":950},[372,373],[131,952,954],{"className":953},[155],[131,955,957,994],{"className":956},[209,210],[131,958,960,991],{"className":959},[214],[131,961,963,977],{"className":962,"style":386},[218],[131,964,965,968],{"style":389},[131,966],{"className":967,"style":312},[226],[131,969,971],{"className":970},[231,232,233,234],[131,972,974],{"className":973},[198,234],[131,975,163],{"className":976},[198,234],[131,978,979,982],{"style":404},[131,980],{"className":981,"style":312},[226],[131,983,985],{"className":984},[231,232,233,234],[131,986,988],{"className":987},[198,234],[131,989,128],{"className":990},[198,267,234],[131,992,272],{"className":993},[271],[131,995,997],{"className":996},[214],[131,998,1000],{"className":999,"style":279},[218],[131,1001],{},[131,1003,1005],{"className":1004,"style":368},[285,367],[131,1006,169],{"className":1007},[372,373],"\niterations to ",[131,1010,1012,1035],{"className":1011},[134],[131,1013,1015],{"className":1014},[138],[140,1016,1017],{"xmlns":142},[144,1018,1019,1032],{},[147,1020,1021],{},[155,1022,1023,1029],{},[165,1024,1025,1027],{},[158,1026,128],{},[161,1028,163],{},[161,1030,1031],{},"4",[173,1033,1034],{"encoding":175},"{\\frac{n^2}{4}}",[131,1036,1038],{"className":1037,"ariaHidden":181},[180],[131,1039,1041,1045],{"className":1040},[185],[131,1042],{"className":1043,"style":1044},[189],"height:1.3629em;vertical-align:-0.345em;",[131,1046,1048],{"className":1047},[198],[131,1049,1051,1054,1144],{"className":1050},[198],[131,1052],{"className":1053},[194,202],[131,1055,1057],{"className":1056},[155],[131,1058,1060,1136],{"className":1059},[209,210],[131,1061,1063,1133],{"className":1062},[214],[131,1064,1067,1081,1089],{"className":1065,"style":1066},[218],"height:1.0179em;",[131,1068,1069,1072],{"style":222},[131,1070],{"className":1071,"style":227},[226],[131,1073,1075],{"className":1074},[231,232,233,234],[131,1076,1078],{"className":1077},[198,234],[131,1079,1031],{"className":1080},[198,234],[131,1082,1083,1086],{"style":243},[131,1084],{"className":1085,"style":227},[226],[131,1087],{"className":1088,"style":251},[250],[131,1090,1091,1094],{"style":254},[131,1092],{"className":1093,"style":227},[226],[131,1095,1097],{"className":1096},[231,232,233,234],[131,1098,1100],{"className":1099},[198,234],[131,1101,1103,1106],{"className":1102},[198,234],[131,1104,128],{"className":1105},[198,267,234],[131,1107,1109],{"className":1108},[295],[131,1110,1112],{"className":1111},[209],[131,1113,1115],{"className":1114},[214],[131,1116,1119],{"className":1117,"style":1118},[218],"height:0.8913em;",[131,1120,1122,1126],{"style":1121},"top:-2.931em;margin-right:0.0714em;",[131,1123],{"className":1124,"style":1125},[226],"height:2.5em;",[131,1127,1130],{"className":1128},[231,1129,373,234],"reset-size3",[131,1131,163],{"className":1132},[198,234],[131,1134,272],{"className":1135},[271],[131,1137,1139],{"className":1138},[214],[131,1140,1142],{"className":1141,"style":279},[218],[131,1143],{},[131,1145],{"className":1146},[285,202]," in the worst case, a two times speed increase\nbarring the overhead to sort the into two lists.",[36,1149,1151],{"id":1150},"the-general-case","The General Case",[15,1153,1154,1155,1158,1159,1161,1162,1165,1166,1168,1169,1172,1176,1177,1179,1176,1181,1183,1176,1186,1188,1190],{},"The current solution only covers cases where ",[126,1156,1157],{},"two"," numbers are added to\nfind our desired sum. However, you may recall that we are also asked to find\nthree addends from the list. Rather than create a tailored solution that\nonly finds three addends I will take this opportunity to extend my algorithm to\nthe general case. That is, I will adapt ",[71,1160,85],{}," to find any ",[126,1163,1164],{},"r"," number\nof entries which sum to our desired number. E.g. where ",[126,1167,1164],{}," = 4 we will be\nlooking for an ",[126,1170,1171],{},"x",[1173,1174,1175],"sub",{},"1"," + ",[126,1178,1171],{},[1173,1180,163],{},[126,1182,1171],{},[1173,1184,1185],{},"3",[126,1187,1171],{},[1173,1189,1031],{},"\nwhich yields our desired number.",[15,1192,1193,1194,1196,1197,1202,1203,1205,1206,34],{},"For ",[71,1195,81],{}," this is incredibly simple as I am using a handy\n",[22,1198,1201],{"href":1199,"rel":1200},"https:\u002F\u002Fcrates.io\u002Fcrates\u002Fitertools",[26],"Rust Itertools"," library which includes a\ncombinations iterator. Here I just pass in ",[126,1204,1164],{}," selections\ninstead of ",[71,1207,163],{},[15,1209,1193,1210,1212,1213,1215],{},[71,1211,85],{}," things get a little more complicated. Remember that for two\nselections we only needed to consider the case ",[71,1214,99],{},". Let's dwell\non why this is for a moment.",[15,1217,1218,1219,1221,1222,1225,1226,1228,1229,92,1232,1235,1236,1238,1239,1242,1243,1246,1247,1249,1250,1252,1253,1249,1255,1257,1258,1261],{},"Consider the following: We are asked to find ",[126,1220,1164],{}," numbers which sum to ",[71,1223,1224],{},"12",".\nWhere ",[126,1227,1164],{}," = 2, ",[71,1230,1231],{},"4 + 8",[71,1233,1234],{},"7 + 5"," are both solutions Notice how ",[71,1237,1031],{}," is 2\nless than half the sum, ",[71,1240,1241],{},"6",",\nand ",[71,1244,1245],{},"8"," is 2 greater than half. In other words the ",[71,1248,95],{}," addend, ",[71,1251,1245],{},",\nmakes up for the deficiency of the ",[71,1254,91],{},[71,1256,1031],{},". In mathematical\nterms we refer to the offset between an addend and the 'half value' as\na ",[126,1259,1260],{},"residual",". So by whatever residual one addend is less than half, the\nother addend is larger than half by that same residual.",[15,1263,1264,1265,1267,1268,1271],{},"Now notice why we compare these values against 'half'. We are asked to\nfind ",[71,1266,163],{}," addends, therefore our residuals are determined by subtracting\n",[71,1269,1270],{},"sum \u002F 2"," from each addend. Using three addends,\nsuch values cannot be all less than or all greater than one third the\ndesired some.",[15,1273,1274,1275,1277,1278,1280,1281,1283,1284,1287,1288,1290,1291,1287,1294,1296,1297,34],{},"E.g. if ",[126,1276,1164],{}," = 3 and our sum was ",[71,1279,1224],{}," a third would be\n",[71,1282,1031],{},". Therefore ",[71,1285,1286],{},"1 + 2 + 3"," (all ",[71,1289,73],{},") and ",[71,1292,1293],{},"5 + 6 + 7",[71,1295,77],{},")\nwill never sum to ",[71,1298,1224],{},[15,1300,1301,1302,1305,1306,34],{},"More generally, the number we compare our entries to is ",[71,1303,1304],{},"sum \u002F r",". But\nwhat should we call such a value? The sum divided by the number of addends,\notherwise known as the ",[126,1307,1308],{},"average",[15,1310,1311,1312,1314,1315,1317],{},"With this in mind we can shift our entire perspective of the situation. For\nevery ",[71,1313,95],{}," value we have a 'positive' residual greater than our average.\nFor every ",[71,1316,91],{}," value we have a 'negative' residual less than our average.\nWhen we sum our addends our positive and negative residuals must cancel (sum to\nzero).",[15,1319,1320,1321,1323,1324,1326,1327,92,1330,1333,1334,1336,1337,34],{},"Let's return to our sum of ",[71,1322,1224],{},", this time considering ",[126,1325,1164],{}," = 3. Valid solutions\ninclude ",[71,1328,1329],{},"6 + 3 + 3",[71,1331,1332],{},"5 + 5 + 2",". Our average is ",[71,1335,1304],{}," or ",[71,1338,1031],{},[15,1340,1341,1342,1344,1345,644,1348,1350,1351,1353,1354,644,1357,1359,1360,1362,1363,1365,1366,1368],{},"For our first solution both ",[71,1343,1185],{},"s have a ",[126,1346,1347],{},"negative",[71,1349,1175],{},"\nresidual with our average and ",[71,1352,1241],{}," has a ",[126,1355,1356],{},"positive",[71,1358,163],{}," residual with our\naverage. Two negative residuals of ",[71,1361,1175],{}," equal a single negative ",[71,1364,163],{},"\nresidual which cancels with our single positive ",[71,1367,163],{}," residual.",[15,1370,1371,1372,1374,1375,1377,1378,1381,1382,1384,1385,1388],{},"A more visual approach: we start with ",[71,1373,1329],{}," and subtract the average ",[71,1376,1031],{},"\nfrom each addend yielding ",[71,1379,1380],{},"2 - 1 - 1",". Each addend now represents the\naforementioned 'residual' with the average. ",[71,1383,1380],{}," then sums to\n",[71,1386,1387],{},"0"," confirming our solution.",[15,1390,1391,1392,1395,1396,34],{},"The possible solutions for three addends assume the form ",[71,1393,1394],{},"small + big + big","\nor ",[71,1397,1398],{},"small + small + big",[15,1400,1401,1402,1405,1406,1409,1410,34],{},"Jumping ahead, for four addends we must consider the\nthree following cases: ",[71,1403,1404],{},"small + big + big + big",", ",[71,1407,1408],{},"small + small + big + big",", and ",[71,1411,1412],{},"small + small + small + big",[15,1414,1415,1416,1418,1419,1421],{},"By now you may have noticed a pattern developing. For two addends we\nconsidered one case, for three addends we considered two cases, and for\nfour addends we consider three cases. More generally, for ",[126,1417,1164],{}," addends\nwe must consider (",[126,1420,1164],{}," - 1) cases.",[15,1423,1424,1425,1427,1428,1431,1432,1435,1436,1439,1440,1442,1443,1446,1447,1544,1545,1547,1548,1645,1646,1648],{},"In practice ",[71,1426,85],{}," will begin by testing all ",[71,1429,1430],{},"1 small + (r - 1) bigs","\nsums, then ",[71,1433,1434],{},"2 smalls + (r - 2) bigs"," up to ",[71,1437,1438],{},"(r - 1) smalls + 1 big"," to find a solution,\nincrementing the number of ",[71,1441,91],{}," addends to use as it goes along. For each\n",[71,1444,1445],{},"i"," number of small addends we compare (",[131,1448,1450,1467],{"className":1449},[134],[131,1451,1453],{"className":1452},[138],[140,1454,1455],{"xmlns":142},[144,1456,1457,1465],{},[147,1458,1459],{},[155,1460,1461,1463],{},[158,1462,128],{},[161,1464,163],{},[173,1466,467],{"encoding":175},[131,1468,1470],{"className":1469,"ariaHidden":181},[180],[131,1471,1473,1476],{"className":1472},[185],[131,1474],{"className":1475,"style":477},[189],[131,1477,1479,1482,1541],{"className":1478},[198],[131,1480],{"className":1481},[194,202],[131,1483,1485],{"className":1484},[155],[131,1486,1488,1533],{"className":1487},[209,210],[131,1489,1491,1530],{"className":1490},[214],[131,1492,1494,1508,1516],{"className":1493,"style":219},[218],[131,1495,1496,1499],{"style":222},[131,1497],{"className":1498,"style":227},[226],[131,1500,1502],{"className":1501},[231,232,233,234],[131,1503,1505],{"className":1504},[198,234],[131,1506,163],{"className":1507},[198,234],[131,1509,1510,1513],{"style":243},[131,1511],{"className":1512,"style":227},[226],[131,1514],{"className":1515,"style":251},[250],[131,1517,1518,1521],{"style":254},[131,1519],{"className":1520,"style":227},[226],[131,1522,1524],{"className":1523},[231,232,233,234],[131,1525,1527],{"className":1526},[198,234],[131,1528,128],{"className":1529},[198,267,234],[131,1531,272],{"className":1532},[271],[131,1534,1536],{"className":1535},[214],[131,1537,1539],{"className":1538,"style":279},[218],[131,1540],{},[131,1542],{"className":1543},[285,202]," choose i) ",[71,1546,73],{},"\nto (",[131,1549,1551,1568],{"className":1550},[134],[131,1552,1554],{"className":1553},[138],[140,1555,1556],{"xmlns":142},[144,1557,1558,1566],{},[147,1559,1560],{},[155,1561,1562,1564],{},[158,1563,128],{},[161,1565,163],{},[173,1567,467],{"encoding":175},[131,1569,1571],{"className":1570,"ariaHidden":181},[180],[131,1572,1574,1577],{"className":1573},[185],[131,1575],{"className":1576,"style":477},[189],[131,1578,1580,1583,1642],{"className":1579},[198],[131,1581],{"className":1582},[194,202],[131,1584,1586],{"className":1585},[155],[131,1587,1589,1634],{"className":1588},[209,210],[131,1590,1592,1631],{"className":1591},[214],[131,1593,1595,1609,1617],{"className":1594,"style":219},[218],[131,1596,1597,1600],{"style":222},[131,1598],{"className":1599,"style":227},[226],[131,1601,1603],{"className":1602},[231,232,233,234],[131,1604,1606],{"className":1605},[198,234],[131,1607,163],{"className":1608},[198,234],[131,1610,1611,1614],{"style":243},[131,1612],{"className":1613,"style":227},[226],[131,1615],{"className":1616,"style":251},[250],[131,1618,1619,1622],{"style":254},[131,1620],{"className":1621,"style":227},[226],[131,1623,1625],{"className":1624},[231,232,233,234],[131,1626,1628],{"className":1627},[198,234],[131,1629,128],{"className":1630},[198,267,234],[131,1632,272],{"className":1633},[271],[131,1635,1637],{"className":1636},[214],[131,1638,1640],{"className":1639,"style":279},[218],[131,1641],{},[131,1643],{"className":1644},[285,202]," choose r - i) ",[71,1647,77],{}," in the worst case.",[15,1650,1651,1652,1654],{},"Performance-wise this puts ",[71,1653,85],{}," at an estimated",[15,1656,1657],{},[131,1658,1660,1747],{"className":1659},[134],[131,1661,1663],{"className":1662},[138],[140,1664,1665],{"xmlns":142},[144,1666,1667,1744],{},[147,1668,1669],{},[1670,1671,1672,1696,1718],"mstyle",{"scriptlevel":1387,"displaystyle":181},[1673,1674,1675,1678,1687],"munderover",{},[150,1676,1677],{},"∑",[147,1679,1680,1682,1685],{},[158,1681,1445],{},[150,1683,1684],{},"=",[161,1686,1175],{},[147,1688,1689,1691,1694],{},[158,1690,1164],{},[150,1692,1693],{},"−",[161,1695,1175],{},[1670,1697,1698],{"scriptlevel":1387,"displaystyle":181},[147,1699,1700,1702,1716],{},[150,1701,153],{"fence":181},[155,1703,1704,1714],{"linethickness":338},[147,1705,1706,1708,1712],{},[158,1707,128],{},[158,1709,1711],{"mathvariant":1710},"normal","\u002F",[161,1713,163],{},[158,1715,1445],{},[150,1717,169],{"fence":181},[1670,1719,1720],{"scriptlevel":1387,"displaystyle":181},[147,1721,1722,1724,1742],{},[150,1723,153],{"fence":181},[155,1725,1726,1734],{"linethickness":338},[147,1727,1728,1730,1732],{},[158,1729,128],{},[158,1731,1711],{"mathvariant":1710},[161,1733,163],{},[147,1735,1736,1738,1740],{},[158,1737,1164],{},[150,1739,1693],{},[158,1741,1445],{},[150,1743,169],{"fence":181},[173,1745,1746],{"encoding":175},"\\displaystyle\\sum_{i=1}^{r-1} \\dbinom{n\u002F2}{i}\\dbinom{n\u002F2}{r - i}",[131,1748,1750],{"className":1749,"ariaHidden":181},[180],[131,1751,1753,1757,1843,1848,1916],{"className":1752},[185],[131,1754],{"className":1755,"style":1756},[189],"height:3.0788em;vertical-align:-1.2777em;",[131,1758,1762],{"className":1759},[1760,1761],"mop","op-limits",[131,1763,1765,1834],{"className":1764},[209,210],[131,1766,1768,1831],{"className":1767},[214],[131,1769,1772,1795,1808],{"className":1770,"style":1771},[218],"height:1.8011em;",[131,1773,1775,1779],{"style":1774},"top:-1.8723em;margin-left:0em;",[131,1776],{"className":1777,"style":1778},[226],"height:3.05em;",[131,1780,1782],{"className":1781},[231,232,233,234],[131,1783,1785,1788,1792],{"className":1784},[198,234],[131,1786,1445],{"className":1787},[198,267,234],[131,1789,1684],{"className":1790},[1791,234],"mrel",[131,1793,1175],{"className":1794},[198,234],[131,1796,1798,1801],{"style":1797},"top:-3.05em;",[131,1799],{"className":1800,"style":1778},[226],[131,1802,1803],{},[131,1804,1677],{"className":1805},[1760,1806,1807],"op-symbol","large-op",[131,1809,1811,1814],{"style":1810},"top:-4.3em;margin-left:0em;",[131,1812],{"className":1813,"style":1778},[226],[131,1815,1817],{"className":1816},[231,232,233,234],[131,1818,1820,1824,1828],{"className":1819},[198,234],[131,1821,1164],{"className":1822,"style":1823},[198,267,234],"margin-right:0.0278em;",[131,1825,1693],{"className":1826},[1827,234],"mbin",[131,1829,1175],{"className":1830},[198,234],[131,1832,272],{"className":1833},[271],[131,1835,1837],{"className":1836},[214],[131,1838,1841],{"className":1839,"style":1840},[218],"height:1.2777em;",[131,1842],{},[131,1844],{"className":1845,"style":1847},[1846],"mspace","margin-right:0.1667em;",[131,1849,1851,1857,1910],{"className":1850},[198],[131,1852,1854],{"className":1853,"style":368},[194,367],[131,1855,153],{"className":1856},[372,233],[131,1858,1860],{"className":1859},[155],[131,1861,1863,1901],{"className":1862},[209,210],[131,1864,1866,1898],{"className":1865},[214],[131,1867,1870,1882],{"className":1868,"style":1869},[218],"height:1.427em;",[131,1871,1873,1876],{"style":1872},"top:-2.314em;",[131,1874],{"className":1875,"style":227},[226],[131,1877,1879],{"className":1878},[198],[131,1880,1445],{"className":1881},[198,267],[131,1883,1885,1888],{"style":1884},"top:-3.677em;",[131,1886],{"className":1887,"style":227},[226],[131,1889,1891,1894],{"className":1890},[198],[131,1892,128],{"className":1893},[198,267],[131,1895,1897],{"className":1896},[198],"\u002F2",[131,1899,272],{"className":1900},[271],[131,1902,1904],{"className":1903},[214],[131,1905,1908],{"className":1906,"style":1907},[218],"height:0.686em;",[131,1909],{},[131,1911,1913],{"className":1912,"style":368},[285,367],[131,1914,169],{"className":1915},[372,233],[131,1917,1919,1925,1987],{"className":1918},[198],[131,1920,1922],{"className":1921,"style":368},[194,367],[131,1923,153],{"className":1924},[372,233],[131,1926,1928],{"className":1927},[155],[131,1929,1931,1978],{"className":1930},[209,210],[131,1932,1934,1975],{"className":1933},[214],[131,1935,1937,1961],{"className":1936,"style":1869},[218],[131,1938,1939,1942],{"style":1872},[131,1940],{"className":1941,"style":227},[226],[131,1943,1945,1948,1952,1955,1958],{"className":1944},[198],[131,1946,1164],{"className":1947,"style":1823},[198,267],[131,1949],{"className":1950,"style":1951},[1846],"margin-right:0.2222em;",[131,1953,1693],{"className":1954},[1827],[131,1956],{"className":1957,"style":1951},[1846],[131,1959,1445],{"className":1960},[198,267],[131,1962,1963,1966],{"style":1884},[131,1964],{"className":1965,"style":227},[226],[131,1967,1969,1972],{"className":1968},[198],[131,1970,128],{"className":1971},[198,267],[131,1973,1897],{"className":1974},[198],[131,1976,272],{"className":1977},[271],[131,1979,1981],{"className":1980},[214],[131,1982,1985],{"className":1983,"style":1984},[218],"height:0.7693em;",[131,1986],{},[131,1988,1990],{"className":1989,"style":368},[285,367],[131,1991,169],{"className":1992},[372,233],[15,1994,1995,1996,1998,1999,2102],{},"iteration count with ",[71,1997,81],{}," still sitting around ",[131,2000,2002,2024],{"className":2001},[134],[131,2003,2005],{"className":2004},[138],[140,2006,2007],{"xmlns":142},[144,2008,2009,2021],{},[147,2010,2011,2013,2019],{},[150,2012,153],{"fence":181},[155,2014,2015,2017],{"linethickness":338},[158,2016,128],{},[158,2018,1164],{},[150,2020,169],{"fence":181},[173,2022,2023],{"encoding":175},"{n \\choose r}",[131,2025,2027],{"className":2026,"ariaHidden":181},[180],[131,2028,2030,2033],{"className":2029},[185],[131,2031],{"className":2032,"style":357},[189],[131,2034,2036],{"className":2035},[198],[131,2037,2039,2045,2096],{"className":2038},[198],[131,2040,2042],{"className":2041,"style":368},[194,367],[131,2043,153],{"className":2044},[372,373],[131,2046,2048],{"className":2047},[155],[131,2049,2051,2088],{"className":2050},[209,210],[131,2052,2054,2085],{"className":2053},[214],[131,2055,2057,2071],{"className":2056,"style":386},[218],[131,2058,2059,2062],{"style":389},[131,2060],{"className":2061,"style":312},[226],[131,2063,2065],{"className":2064},[231,232,233,234],[131,2066,2068],{"className":2067},[198,234],[131,2069,1164],{"className":2070,"style":1823},[198,267,234],[131,2072,2073,2076],{"style":404},[131,2074],{"className":2075,"style":312},[226],[131,2077,2079],{"className":2078},[231,232,233,234],[131,2080,2082],{"className":2081},[198,234],[131,2083,128],{"className":2084},[198,267,234],[131,2086,272],{"className":2087},[271],[131,2089,2091],{"className":2090},[214],[131,2092,2094],{"className":2093,"style":279},[218],[131,2095],{},[131,2097,2099],{"className":2098,"style":368},[285,367],[131,2100,169],{"className":2101},[372,373],"\niterations.",[15,2104,2105,2106,2108,2109,2114,2115,2117,2118,2120,2121,2123],{},"It turns out as ",[126,2107,1164],{}," approaches infinity these two expressions actually\n",[22,2110,2113],{"href":2111,"rel":2112},"https:\u002F\u002Fmath.stackexchange.com\u002Fquestions\u002F962710\u002Fsum-of-the-product-of-two-combinations",[26],"converge","\nmeaning so long as ",[126,2116,1164],{}," is kept below infinity and memory allocations and sorting\noverhead are kept in check ",[71,2119,85],{}," should out-perform ",[71,2122,81],{}," on average.",[36,2125,2127],{"id":2126},"dealing-with-edge-cases","Dealing with Edge Cases",[15,2129,2130,2131,2133,2134,92,2136,2138,2139,2142],{},"Allow me to take a step back and revisit the core principle of my approach.\nBefore any comparisons are made ",[71,2132,85],{}," first separates the initial\nlist of inputs into ",[71,2135,73],{},[71,2137,77],{}," depending on whether the values are less\nthan or greater than our average respectively, but how should we handle cases\nwhere an input is ",[60,2140,2141],{},"equal to"," our average?",[15,2144,2145,2146,2149,2150,2152,2153,2156],{},"Let's call such numbers ",[71,2147,2148],{},"perfects",". In previous versions of ",[71,2151,85],{}," I had performed\nmathematical gymnastics and even recursion to cover all ",[71,2154,2155],{},"perfect"," cases. However,\nwhile writing this article and working to optimize my implementation a far simpler\napproach struck me.",[15,2158,2159,2160,92,2162,2164,2165,2167,2168,2170,2171,2173,2174,2176,2177,2179],{},"While sorting our inputs into ",[71,2161,77],{},[71,2163,73],{}," if a ",[71,2166,2155],{}," value is found place\nit into the ",[71,2169,77],{}," list. Then if another ",[71,2172,2155],{}," value is found place it into the\n",[71,2175,73],{}," list. Repeat this alternating pattern for all ",[71,2178,2155],{}," values.",[15,2181,1193,2182,2184,2185,2187,2188,2190,2191,2193,2194,2196,2197,2193,2199,2201],{},[126,2183,1164],{}," = 2 addends we compare ",[71,2186,99],{},". If we find two ",[71,2189,2148],{}," then the\n",[71,2192,2155],{}," in the ",[71,2195,73],{}," list and the ",[71,2198,2155],{},[71,2200,77],{}," list will be compared\naccording to this form and produce a solution.",[15,2203,2204,2205,2207,2208,92,2210,2212,2213,2215,2216,2218,2219,2221],{},"Likewise for ",[126,2206,1164],{}," = 3 addends we compare ",[71,2209,1394],{},[71,2211,1398],{},".\nThe ",[71,2214,77],{}," list will end up with two ",[71,2217,2155],{}," values (due to alternation). Therefore,\nwhile iterating through all ",[71,2220,1394],{}," combinations of values we will make\nthe comparison over perfect values.",[15,2223,2224,2225,2227,2228,2230,2231,2233,2234,2236,2237,2239,2240,2242,2243,2245,2246,2248,2249,2251,2252,92,2254,2256],{},"For any number of ",[71,2226,2155],{}," inputs found there will be at most one more ",[71,2229,2155],{}," in\nthe ",[71,2232,77],{}," list or an equal number of ",[71,2235,2148],{}," in each list. Since ",[71,2238,85],{},"\ncovers all combinations of addends from one ",[71,2241,91],{}," to one ",[71,2244,95],{},"\naddend we are guaranteed to cover all cases with one more ",[71,2247,95],{}," addend than ",[71,2250,91],{},"\naddends or equal ",[71,2253,91],{},[71,2255,95],{}," addends.",[15,2258,2259,2260,2262,2263,2265,2266,2268,2269,2271,2272,92,2274,2276,2277,2280,2281,2283,2284,2286,2287,2289,2290,2292,2293,647,2295,644,2297,34],{},"Finally, reconsider ",[71,2261,2155],{}," values as an addend with a ",[71,2264,1387],{}," residual with the average.\nAs such, when searching for ",[71,2267,1185],{}," addends our solution may contain only one ",[71,2270,2155],{},"\nso long as the remaining ",[71,2273,95],{},[71,2275,91],{}," addends cancel with each other. The\n",[71,2278,2279],{},"big + big + small"," case will cover this scenario since the ",[71,2282,95],{}," addends test ALL\nvalues in the ",[71,2285,77],{}," list including the ",[71,2288,2155],{}," values stored therein. We can\nrest assured ",[71,2291,85],{}," has complete coverage from one ",[71,2294,2155],{},[126,2296,1164],{},[71,2298,2148],{},[15,2300,2301,2302,2304],{},"Since our ",[71,2303,2155],{}," values are incorporated nicely into `find_addends we manage\nto perform no extra steps outside of toggling a boolean value while sorting our\ninputs. Therefore, dealing with this edge case added a negligible performance impact.",[36,2306,2308],{"id":2307},"part-one-conclusion","Part One - Conclusion",[15,2310,2311,2312,2314,2315,2317,2318,2320],{},"To test the validity of my mathematical models I created a test input which contains\n100 elements, 51 ",[71,2313,73],{},", 49 ",[71,2316,77],{},", and five correct addends. Furthermore, this input\nplaces the correct addends at the very end of the file and uses 4 ",[71,2319,91],{}," addends. This\nought to produce the worst-case iteration count for both algorithms which the models\nseek to calculate.",[15,2322,2323,2324,2329,2330,2332,2333,2335],{},"Entering this data into ",[22,2325,2328],{"href":2326,"rel":2327},"https:\u002F\u002Fwww.wolframalpha.com\u002Finput\u002F?i=sum+%28%2851+choose+i%29%2849+choose+5-i%29%29%2C+i%3D1+to+4",[26],"WolframAlpha","\nyields 71031576 using the ",[71,2331,85],{}," model and 75287520 using the ",[71,2334,81],{}," model.",[15,2337,2338],{},"Running the test input through both algorithms and counting the iterations outputs:",[2340,2341,2346],"pre",{"className":2342,"code":2344,"language":2345},[2343],"language-text","find_addends completed in 75808 ms with 71031576 iterations\nsolution set: [10.0, 10.0, 10.0, 10.0, 1980.0], sum: 2020, product: 19800000\nuse_combos completed in 87519 ms with 75287520 iterations\nsolution_set: [10.0, 10.0, 10.0, 10.0, 1980.0], sum: 2020, product: 19800000\n","text",[71,2347,2344],{"__ignoreMap":2348},"",[15,2350,2351],{},"Both values match exactly with their respective model which implies these models\nare accurate.",[15,2353,2354,2355,2357,2358,2360],{},"Therefore, the performance of ",[71,2356,85],{}," versus ",[71,2359,81],{}," should resemble the\nfollowing formulas.",[2362,2363,2365],"div",{"style":2364},"overflow-x: scroll;",[2366,2367,2369,2370],"table",{"style":2368},"width: 100%; text-align: center; line-height: 3rem;","\n  ",[2371,2372,2373,2369,2385,2369,2806],"tbody",{},[2374,2375,2376,2377,2376,2380,2376,2383,2369],"tr",{},"\n    ",[2378,2379],"th",{},[2378,2381,85],{"style":2382},"border-bottom: solid white 1px;",[2378,2384,81],{"style":2382},[2374,2386,2376,2387,2392,2701,2369],{},[2388,2389,2391],"td",{"style":2390},"border-right: solid white 1px;","Iterations",[2388,2393,2394],{},[15,2395,2396],{},[131,2397,2399,2478],{"className":2398},[134],[131,2400,2402],{"className":2401},[138],[140,2403,2404],{"xmlns":142},[144,2405,2406,2476],{},[147,2407,2408],{},[1670,2409,2410,2430,2450],{"scriptlevel":1387,"displaystyle":181},[1673,2411,2412,2414,2422],{},[150,2413,1677],{},[147,2415,2416,2418,2420],{},[158,2417,1445],{},[150,2419,1684],{},[161,2421,1175],{},[147,2423,2424,2426,2428],{},[158,2425,1164],{},[150,2427,1693],{},[161,2429,1175],{},[1670,2431,2432],{"scriptlevel":1387,"displaystyle":181},[147,2433,2434,2436,2448],{},[150,2435,153],{"fence":181},[155,2437,2438,2446],{"linethickness":338},[147,2439,2440,2442,2444],{},[158,2441,128],{},[158,2443,1711],{"mathvariant":1710},[161,2445,163],{},[158,2447,1445],{},[150,2449,169],{"fence":181},[1670,2451,2452],{"scriptlevel":1387,"displaystyle":181},[147,2453,2454,2456,2474],{},[150,2455,153],{"fence":181},[155,2457,2458,2466],{"linethickness":338},[147,2459,2460,2462,2464],{},[158,2461,128],{},[158,2463,1711],{"mathvariant":1710},[161,2465,163],{},[147,2467,2468,2470,2472],{},[158,2469,1164],{},[150,2471,1693],{},[158,2473,1445],{},[150,2475,169],{"fence":181},[173,2477,1746],{"encoding":175},[131,2479,2481],{"className":2480,"ariaHidden":181},[180],[131,2482,2484,2487,2560,2563,2626],{"className":2483},[185],[131,2485],{"className":2486,"style":1756},[189],[131,2488,2490],{"className":2489},[1760,1761],[131,2491,2493,2552],{"className":2492},[209,210],[131,2494,2496,2549],{"className":2495},[214],[131,2497,2499,2519,2529],{"className":2498,"style":1771},[218],[131,2500,2501,2504],{"style":1774},[131,2502],{"className":2503,"style":1778},[226],[131,2505,2507],{"className":2506},[231,232,233,234],[131,2508,2510,2513,2516],{"className":2509},[198,234],[131,2511,1445],{"className":2512},[198,267,234],[131,2514,1684],{"className":2515},[1791,234],[131,2517,1175],{"className":2518},[198,234],[131,2520,2521,2524],{"style":1797},[131,2522],{"className":2523,"style":1778},[226],[131,2525,2526],{},[131,2527,1677],{"className":2528},[1760,1806,1807],[131,2530,2531,2534],{"style":1810},[131,2532],{"className":2533,"style":1778},[226],[131,2535,2537],{"className":2536},[231,232,233,234],[131,2538,2540,2543,2546],{"className":2539},[198,234],[131,2541,1164],{"className":2542,"style":1823},[198,267,234],[131,2544,1693],{"className":2545},[1827,234],[131,2547,1175],{"className":2548},[198,234],[131,2550,272],{"className":2551},[271],[131,2553,2555],{"className":2554},[214],[131,2556,2558],{"className":2557,"style":1840},[218],[131,2559],{},[131,2561],{"className":2562,"style":1847},[1846],[131,2564,2566,2572,2620],{"className":2565},[198],[131,2567,2569],{"className":2568,"style":368},[194,367],[131,2570,153],{"className":2571},[372,233],[131,2573,2575],{"className":2574},[155],[131,2576,2578,2612],{"className":2577},[209,210],[131,2579,2581,2609],{"className":2580},[214],[131,2582,2584,2595],{"className":2583,"style":1869},[218],[131,2585,2586,2589],{"style":1872},[131,2587],{"className":2588,"style":227},[226],[131,2590,2592],{"className":2591},[198],[131,2593,1445],{"className":2594},[198,267],[131,2596,2597,2600],{"style":1884},[131,2598],{"className":2599,"style":227},[226],[131,2601,2603,2606],{"className":2602},[198],[131,2604,128],{"className":2605},[198,267],[131,2607,1897],{"className":2608},[198],[131,2610,272],{"className":2611},[271],[131,2613,2615],{"className":2614},[214],[131,2616,2618],{"className":2617,"style":1907},[218],[131,2619],{},[131,2621,2623],{"className":2622,"style":368},[285,367],[131,2624,169],{"className":2625},[372,233],[131,2627,2629,2635,2695],{"className":2628},[198],[131,2630,2632],{"className":2631,"style":368},[194,367],[131,2633,153],{"className":2634},[372,233],[131,2636,2638],{"className":2637},[155],[131,2639,2641,2687],{"className":2640},[209,210],[131,2642,2644,2684],{"className":2643},[214],[131,2645,2647,2670],{"className":2646,"style":1869},[218],[131,2648,2649,2652],{"style":1872},[131,2650],{"className":2651,"style":227},[226],[131,2653,2655,2658,2661,2664,2667],{"className":2654},[198],[131,2656,1164],{"className":2657,"style":1823},[198,267],[131,2659],{"className":2660,"style":1951},[1846],[131,2662,1693],{"className":2663},[1827],[131,2665],{"className":2666,"style":1951},[1846],[131,2668,1445],{"className":2669},[198,267],[131,2671,2672,2675],{"style":1884},[131,2673],{"className":2674,"style":227},[226],[131,2676,2678,2681],{"className":2677},[198],[131,2679,128],{"className":2680},[198,267],[131,2682,1897],{"className":2683},[198],[131,2685,272],{"className":2686},[271],[131,2688,2690],{"className":2689},[214],[131,2691,2693],{"className":2692,"style":1984},[218],[131,2694],{},[131,2696,2698],{"className":2697,"style":368},[285,367],[131,2699,169],{"className":2700},[372,233],[2388,2702,2703],{},[131,2704,2706,2732],{"className":2705},[134],[131,2707,2709],{"className":2708},[138],[140,2710,2711],{"xmlns":142},[144,2712,2713,2729],{},[147,2714,2715],{},[1670,2716,2717],{"scriptlevel":1387,"displaystyle":181},[147,2718,2719,2721,2727],{},[150,2720,153],{"fence":181},[155,2722,2723,2725],{"linethickness":338},[158,2724,128],{},[158,2726,1164],{},[150,2728,169],{"fence":181},[173,2730,2731],{"encoding":175},"{ \\dbinom{n}{r} }",[131,2733,2735],{"className":2734,"ariaHidden":181},[180],[131,2736,2738,2742],{"className":2737},[185],[131,2739],{"className":2740,"style":2741},[189],"height:2.4em;vertical-align:-0.95em;",[131,2743,2745],{"className":2744},[198],[131,2746,2748,2754,2800],{"className":2747},[198],[131,2749,2751],{"className":2750,"style":368},[194,367],[131,2752,153],{"className":2753},[372,233],[131,2755,2757],{"className":2756},[155],[131,2758,2760,2792],{"className":2759},[209,210],[131,2761,2763,2789],{"className":2762},[214],[131,2764,2767,2778],{"className":2765,"style":2766},[218],"height:1.1076em;",[131,2768,2769,2772],{"style":1872},[131,2770],{"className":2771,"style":227},[226],[131,2773,2775],{"className":2774},[198],[131,2776,1164],{"className":2777,"style":1823},[198,267],[131,2779,2780,2783],{"style":1884},[131,2781],{"className":2782,"style":227},[226],[131,2784,2786],{"className":2785},[198],[131,2787,128],{"className":2788},[198,267],[131,2790,272],{"className":2791},[271],[131,2793,2795],{"className":2794},[214],[131,2796,2798],{"className":2797,"style":1907},[218],[131,2799],{},[131,2801,2803],{"className":2802,"style":368},[285,367],[131,2804,169],{"className":2805},[372,233],[2374,2807,2376,2808,2376,2811,2376,2896,2369],{},[2388,2809,2810],{"style":2390},"Big O",[2388,2812,2813],{},[15,2814,2815],{},[131,2816,2818,2843],{"className":2817},[134],[131,2819,2821],{"className":2820},[138],[140,2822,2823],{"xmlns":142},[144,2824,2825,2840],{},[147,2826,2827,2830,2832,2838],{},[158,2828,2829],{"mathvariant":1710},"O",[150,2831,153],{"stretchy":152},[165,2833,2834,2836],{},[158,2835,128],{},[158,2837,1164],{},[150,2839,169],{"stretchy":152},[173,2841,2842],{"encoding":175},"{ \\Omicron(n^r) }",[131,2844,2846],{"className":2845,"ariaHidden":181},[180],[131,2847,2849,2853],{"className":2848},[185],[131,2850],{"className":2851,"style":2852},[189],"height:1em;vertical-align:-0.25em;",[131,2854,2856,2860,2863,2893],{"className":2855},[198],[131,2857,2829],{"className":2858},[198,2859],"mathrm",[131,2861,153],{"className":2862},[194],[131,2864,2866,2869],{"className":2865},[198],[131,2867,128],{"className":2868},[198,267],[131,2870,2872],{"className":2871},[295],[131,2873,2875],{"className":2874},[209],[131,2876,2878],{"className":2877},[214],[131,2879,2882],{"className":2880,"style":2881},[218],"height:0.6644em;",[131,2883,2884,2887],{"style":308},[131,2885],{"className":2886,"style":312},[226],[131,2888,2890],{"className":2889},[231,232,233,234],[131,2891,1164],{"className":2892,"style":1823},[198,267,234],[131,2894,169],{"className":2895},[285],[2388,2897,2898],{},[15,2899,2900],{},[131,2901,2903,2926],{"className":2902},[134],[131,2904,2906],{"className":2905},[138],[140,2907,2908],{"xmlns":142},[144,2909,2910,2924],{},[147,2911,2912,2914,2916,2922],{},[158,2913,2829],{"mathvariant":1710},[150,2915,153],{"stretchy":152},[165,2917,2918,2920],{},[158,2919,128],{},[158,2921,1164],{},[150,2923,169],{"stretchy":152},[173,2925,2842],{"encoding":175},[131,2927,2929],{"className":2928,"ariaHidden":181},[180],[131,2930,2932,2935],{"className":2931},[185],[131,2933],{"className":2934,"style":2852},[189],[131,2936,2938,2941,2944,2973],{"className":2937},[198],[131,2939,2829],{"className":2940},[198,2859],[131,2942,153],{"className":2943},[194],[131,2945,2947,2950],{"className":2946},[198],[131,2948,128],{"className":2949},[198,267],[131,2951,2953],{"className":2952},[295],[131,2954,2956],{"className":2955},[209],[131,2957,2959],{"className":2958},[214],[131,2960,2962],{"className":2961,"style":2881},[218],[131,2963,2964,2967],{"style":308},[131,2965],{"className":2966,"style":312},[226],[131,2968,2970],{"className":2969},[231,232,233,234],[131,2971,1164],{"className":2972,"style":1823},[198,267,234],[131,2974,169],{"className":2975},[285],[2977,2978],"br",{},[15,2980,2981,2982,2984,2985,2987,2988,2990,2991,2993,2994,647,3094,3153,3154,3434,3435,3437,3438,319,3602,34],{},"Although I was hoping for a larger performance lead than calculated ",[71,2983,85],{},"\nstill manages to remove the \"all ",[71,2986,91],{},"\" and \"all ",[71,2989,95],{},"\" combinations and prove\nto be more efficient than ",[71,2992,81],{},".\nHowever, simplifying the number of combinations from the form\n",[131,2995,2997,3019],{"className":2996},[134],[131,2998,3000],{"className":2999},[138],[140,3001,3002],{"xmlns":142},[144,3003,3004,3016],{},[147,3005,3006,3008,3014],{},[150,3007,153],{"fence":181},[155,3009,3010,3012],{"linethickness":338},[158,3011,128],{},[158,3013,1445],{},[150,3015,169],{"fence":181},[173,3017,3018],{"encoding":175},"n \\choose i",[131,3020,3022],{"className":3021,"ariaHidden":181},[180],[131,3023,3025,3028],{"className":3024},[185],[131,3026],{"className":3027,"style":357},[189],[131,3029,3031,3037,3088],{"className":3030},[198],[131,3032,3034],{"className":3033,"style":368},[194,367],[131,3035,153],{"className":3036},[372,373],[131,3038,3040],{"className":3039},[155],[131,3041,3043,3080],{"className":3042},[209,210],[131,3044,3046,3077],{"className":3045},[214],[131,3047,3049,3063],{"className":3048,"style":386},[218],[131,3050,3051,3054],{"style":389},[131,3052],{"className":3053,"style":312},[226],[131,3055,3057],{"className":3056},[231,232,233,234],[131,3058,3060],{"className":3059},[198,234],[131,3061,1445],{"className":3062},[198,267,234],[131,3064,3065,3068],{"style":404},[131,3066],{"className":3067,"style":312},[226],[131,3069,3071],{"className":3070},[231,232,233,234],[131,3072,3074],{"className":3073},[198,234],[131,3075,128],{"className":3076},[198,267,234],[131,3078,272],{"className":3079},[271],[131,3081,3083],{"className":3082},[214],[131,3084,3086],{"className":3085,"style":279},[218],[131,3087],{},[131,3089,3091],{"className":3090,"style":368},[285,367],[131,3092,169],{"className":3093},[372,373],[131,3095,3097,3115],{"className":3096},[134],[131,3098,3100],{"className":3099},[138],[140,3101,3102],{"xmlns":142},[144,3103,3104,3112],{},[147,3105,3106],{},[165,3107,3108,3110],{},[158,3109,128],{},[158,3111,1164],{},[173,3113,3114],{"encoding":175},"n^r",[131,3116,3118],{"className":3117,"ariaHidden":181},[180],[131,3119,3121,3124],{"className":3120},[185],[131,3122],{"className":3123,"style":2881},[189],[131,3125,3127,3130],{"className":3126},[198],[131,3128,128],{"className":3129},[198,267],[131,3131,3133],{"className":3132},[295],[131,3134,3136],{"className":3135},[209],[131,3137,3139],{"className":3138},[214],[131,3140,3142],{"className":3141,"style":2881},[218],[131,3143,3144,3147],{"style":308},[131,3145],{"className":3146,"style":312},[226],[131,3148,3150],{"className":3149},[231,232,233,234],[131,3151,1164],{"className":3152,"style":1823},[198,267,234]," we might expect ",[131,3155,3157,3202],{"className":3156},[134],[131,3158,3160],{"className":3159},[138],[140,3161,3162],{"xmlns":142},[144,3163,3164,3199],{},[147,3165,3166,3176,3179],{},[165,3167,3168,3174],{},[155,3169,3170,3172],{},[158,3171,128],{},[161,3173,163],{},[158,3175,1445],{},[150,3177,3178],{},"∗",[165,3180,3181,3187],{},[155,3182,3183,3185],{},[158,3184,128],{},[161,3186,163],{},[147,3188,3189,3191,3193,3195,3197],{},[150,3190,153],{"stretchy":152},[158,3192,1164],{},[150,3194,1693],{},[158,3196,1445],{},[150,3198,169],{"stretchy":152},[173,3200,3201],{"encoding":175},"\\frac{n}{2}^i * \\frac{n}{2}^{(r - i)}",[131,3203,3205,3317],{"className":3204,"ariaHidden":181},[180],[131,3206,3208,3212,3308,3311,3314],{"className":3207},[185],[131,3209],{"className":3210,"style":3211},[189],"height:1.255em;vertical-align:-0.345em;",[131,3213,3215,3283],{"className":3214},[198],[131,3216,3218,3221,3280],{"className":3217},[198],[131,3219],{"className":3220},[194,202],[131,3222,3224],{"className":3223},[155],[131,3225,3227,3272],{"className":3226},[209,210],[131,3228,3230,3269],{"className":3229},[214],[131,3231,3233,3247,3255],{"className":3232,"style":219},[218],[131,3234,3235,3238],{"style":222},[131,3236],{"className":3237,"style":227},[226],[131,3239,3241],{"className":3240},[231,232,233,234],[131,3242,3244],{"className":3243},[198,234],[131,3245,163],{"className":3246},[198,234],[131,3248,3249,3252],{"style":243},[131,3250],{"className":3251,"style":227},[226],[131,3253],{"className":3254,"style":251},[250],[131,3256,3257,3260],{"style":254},[131,3258],{"className":3259,"style":227},[226],[131,3261,3263],{"className":3262},[231,232,233,234],[131,3264,3266],{"className":3265},[198,234],[131,3267,128],{"className":3268},[198,267,234],[131,3270,272],{"className":3271},[271],[131,3273,3275],{"className":3274},[214],[131,3276,3278],{"className":3277,"style":279},[218],[131,3279],{},[131,3281],{"className":3282},[285,202],[131,3284,3286],{"className":3285},[295],[131,3287,3289],{"className":3288},[209],[131,3290,3292],{"className":3291},[214],[131,3293,3296],{"className":3294,"style":3295},[218],"height:0.91em;",[131,3297,3299,3302],{"style":3298},"top:-3.1483em;margin-right:0.05em;",[131,3300],{"className":3301,"style":312},[226],[131,3303,3305],{"className":3304},[231,232,233,234],[131,3306,1445],{"className":3307},[198,267,234],[131,3309],{"className":3310,"style":1951},[1846],[131,3312,3178],{"className":3313},[1827],[131,3315],{"className":3316,"style":1951},[1846],[131,3318,3320,3324],{"className":3319},[185],[131,3321],{"className":3322,"style":3323},[189],"height:1.3183em;vertical-align:-0.345em;",[131,3325,3327,3395],{"className":3326},[198],[131,3328,3330,3333,3392],{"className":3329},[198],[131,3331],{"className":3332},[194,202],[131,3334,3336],{"className":3335},[155],[131,3337,3339,3384],{"className":3338},[209,210],[131,3340,3342,3381],{"className":3341},[214],[131,3343,3345,3359,3367],{"className":3344,"style":219},[218],[131,3346,3347,3350],{"style":222},[131,3348],{"className":3349,"style":227},[226],[131,3351,3353],{"className":3352},[231,232,233,234],[131,3354,3356],{"className":3355},[198,234],[131,3357,163],{"className":3358},[198,234],[131,3360,3361,3364],{"style":243},[131,3362],{"className":3363,"style":227},[226],[131,3365],{"className":3366,"style":251},[250],[131,3368,3369,3372],{"style":254},[131,3370],{"className":3371,"style":227},[226],[131,3373,3375],{"className":3374},[231,232,233,234],[131,3376,3378],{"className":3377},[198,234],[131,3379,128],{"className":3380},[198,267,234],[131,3382,272],{"className":3383},[271],[131,3385,3387],{"className":3386},[214],[131,3388,3390],{"className":3389,"style":279},[218],[131,3391],{},[131,3393],{"className":3394},[285,202],[131,3396,3398],{"className":3397},[295],[131,3399,3401],{"className":3400},[209],[131,3402,3404],{"className":3403},[214],[131,3405,3408],{"className":3406,"style":3407},[218],"height:0.9733em;",[131,3409,3410,3413],{"style":3298},[131,3411],{"className":3412,"style":312},[226],[131,3414,3416],{"className":3415},[231,232,233,234],[131,3417,3419,3422,3425,3428,3431],{"className":3418},[198,234],[131,3420,153],{"className":3421},[194,234],[131,3423,1164],{"className":3424,"style":1823},[198,267,234],[131,3426,1693],{"className":3427},[1827,234],[131,3429,1445],{"className":3430},[198,267,234],[131,3432,169],{"className":3433},[285,234],"\niterations times the number of ",[71,3436,91],{}," addends we consider. This yields roughly\n",[131,3439,3441,3473],{"className":3440},[134],[131,3442,3444],{"className":3443},[138],[140,3445,3446],{"xmlns":142},[144,3447,3448,3470],{},[147,3449,3450,3462,3464],{},[155,3451,3452,3460],{},[147,3453,3454,3456,3458],{},[158,3455,1164],{},[150,3457,1693],{},[161,3459,1175],{},[161,3461,1031],{},[150,3463,3178],{},[165,3465,3466,3468],{},[158,3467,128],{},[158,3469,1164],{},[173,3471,3472],{"encoding":175},"\\frac{r - 1}{4} * n^r",[131,3474,3476,3567],{"className":3475,"ariaHidden":181},[180],[131,3477,3479,3483,3558,3561,3564],{"className":3478},[185],[131,3480],{"className":3481,"style":3482},[189],"height:1.1901em;vertical-align:-0.345em;",[131,3484,3486,3489,3555],{"className":3485},[198],[131,3487],{"className":3488},[194,202],[131,3490,3492],{"className":3491},[155],[131,3493,3495,3547],{"className":3494},[209,210],[131,3496,3498,3544],{"className":3497},[214],[131,3499,3502,3516,3524],{"className":3500,"style":3501},[218],"height:0.8451em;",[131,3503,3504,3507],{"style":222},[131,3505],{"className":3506,"style":227},[226],[131,3508,3510],{"className":3509},[231,232,233,234],[131,3511,3513],{"className":3512},[198,234],[131,3514,1031],{"className":3515},[198,234],[131,3517,3518,3521],{"style":243},[131,3519],{"className":3520,"style":227},[226],[131,3522],{"className":3523,"style":251},[250],[131,3525,3526,3529],{"style":254},[131,3527],{"className":3528,"style":227},[226],[131,3530,3532],{"className":3531},[231,232,233,234],[131,3533,3535,3538,3541],{"className":3534},[198,234],[131,3536,1164],{"className":3537,"style":1823},[198,267,234],[131,3539,1693],{"className":3540},[1827,234],[131,3542,1175],{"className":3543},[198,234],[131,3545,272],{"className":3546},[271],[131,3548,3550],{"className":3549},[214],[131,3551,3553],{"className":3552,"style":279},[218],[131,3554],{},[131,3556],{"className":3557},[285,202],[131,3559],{"className":3560,"style":1951},[1846],[131,3562,3178],{"className":3563},[1827],[131,3565],{"className":3566,"style":1951},[1846],[131,3568,3570,3573],{"className":3569},[185],[131,3571],{"className":3572,"style":2881},[189],[131,3574,3576,3579],{"className":3575},[198],[131,3577,128],{"className":3578},[198,267],[131,3580,3582],{"className":3581},[295],[131,3583,3585],{"className":3584},[209],[131,3586,3588],{"className":3587},[214],[131,3589,3591],{"className":3590,"style":2881},[218],[131,3592,3593,3596],{"style":308},[131,3594],{"className":3595,"style":312},[226],[131,3597,3599],{"className":3598},[231,232,233,234],[131,3600,1164],{"className":3601,"style":1823},[198,267,234],[71,3603,85],{},[15,3605,3606,3607,3660,3661,92,3663,3665],{},"In other words, as ",[131,3608,3610,3628],{"className":3609},[134],[131,3611,3613],{"className":3612},[138],[140,3614,3615],{"xmlns":142},[144,3616,3617,3625],{},[147,3618,3619,3621,3623],{},[158,3620,1164],{},[150,3622,1693],{},[161,3624,1175],{},[173,3626,3627],{"encoding":175},"r - 1",[131,3629,3631,3650],{"className":3630,"ariaHidden":181},[180],[131,3632,3634,3638,3641,3644,3647],{"className":3633},[185],[131,3635],{"className":3636,"style":3637},[189],"height:0.6667em;vertical-align:-0.0833em;",[131,3639,1164],{"className":3640,"style":1823},[198,267],[131,3642],{"className":3643,"style":1951},[1846],[131,3645,1693],{"className":3646},[1827],[131,3648],{"className":3649,"style":1951},[1846],[131,3651,3653,3657],{"className":3652},[185],[131,3654],{"className":3655,"style":3656},[189],"height:0.6444em;",[131,3658,1175],{"className":3659},[198]," exceeds 4 performance gains become increasingly negligible\nbut as the difference in the number of ",[71,3662,73],{},[71,3664,77],{}," increases performance\ngreatly improves.",[15,3667,3668,3669,3671,3672,3675],{},"Despite these shortcomings this exercise has been far from fruitless. As I will detail\nin future posts ",[71,3670,85],{}," actually manages to hit upon several key ideas leveraged\nby leading ",[126,3673,3674],{},"k","-SUM algorithms.",[15,3677,3678,3679,3684,3685,3689,3690],{},"There is plenty more analysis I would like to share in the following parts so keep an\neye out on ",[22,3680,3683],{"href":3681,"rel":3682},"https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Faarussoexe\u002F",[26],"LinkedIn"," and thank you for reading!\nI hope this post was interesting and the explanations clear.\nIf you have any questions or comments please feel free to ",[22,3686,3688],{"href":3687},"\u002Fcontact","contact me",".\nUntil ",[3691,3692,3693],"r-end-mark",{},"later!",{"title":2348,"searchDepth":3695,"depth":3695,"links":3696},2,[],"2021-05-04","This series of posts outlines one of my more technical projects to date. I attempt to solve a puzzle using two approaches. My goal is to optimize my custom approach until it can consistently outperform the more traditional approach on a variety of data sets. I anticipate this will require a rather long explanation so this project will come in parts.","md",{},true,"\u002Fprojects\u002Ffind-addends-1",{"title":5,"description":2348},"projects\u002Ffind-addends-1","Explaining my approach","gb0YIZueqc6Nb1x7c3-lN-tlJhFLibNWLcc3TAD2490",1795897778749,"b3255129-28b9-467a-bcff-9c26f3b3566d"]