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.
I found a way mathmateically to calculate the number of ALL combinations where order does not matter. I meant to subtract the number of quadruples where each number XOR = 0 from that total, but it turns out it isn't easy to find that.
defsum_range(start,end):#integer skipsstart,end=sorted([start,end])return(end-start+1)*(start+end)//2deffindTotal(a,b,c,d):#because a,b,c,d is sorted, d is maxbase=d-c+1same_frequency_as_bass=d-(b-1)same_frequency_sum=sum_range(base,same_frequency_as_bass)*sum_range(b-a+1,b)staggered_sum=0freq=0foriinrange(0,b-1):#rememberthatrangeis[).freq+=min([i+1,a])staggered_sum+=(d-i)*freqreturnsame_frequency_sum+staggered_sum
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Quadruples
You are viewing a single comment's thread. Return to all comments →
I found a way mathmateically to calculate the number of ALL combinations where order does not matter. I meant to subtract the number of quadruples where each number XOR = 0 from that total, but it turns out it isn't easy to find that.