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.
anyone can help me to explain this?
this is my temporary solution
myDropWhile::(a->Bool)->[a]->[a]myDropWhile_[]=[]myDropWhilef(x:xs)|fx=myDropWhilefxs|otherwise=x:myDropWhilefxsupperLimit::(Integrala)=>aupperLimit=round.sqrt$1000powerNat::(Integrala)=>a->a->[a]->[a]powerNatab|a<1=error"out of scope"|a>1000=error"out of scope"|b<2=error"out of scope"|b>10=error"out of scope"|otherwise=foldr(\xacc->if(((x^b)+(sum.map(^b)$acc))<=a)thenx:accelseacc)[]uniquePowerNats::(Integrala)=>a->a->[a]->[[a]]uniquePowerNats__[]=[]uniquePowerNatsabxs=natNum:uniquePowerNatsab(restNumxs)wherenatNum=powerNatabxsrestNum=(\ys->if((sum.map(^b)$natNum)==a)thenfilter(<(lastnatNum))$myDropWhile(`elem`natNum)xselsetake((lengthxs)-1)xs)main=doa<-getLineb<-getLineletnum=reada::Intletpow=readb::IntputStrLn$show.length.filter(\xs->(sum.map(^pow)$xs)==num).uniquePowerNatsnumpow$[1..upperLimit]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Sums of Powers
You are viewing a single comment's thread. Return to all comments →
input --> 400 2
expected output --> 55
anyone can help me to explain this? this is my temporary solution