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 tried doing this with common-lisp and realised there no string spliting function in standard lib lol.
;;SOLUTION(defunsuper-digit(int-str)"Parse each char of INT-STR as int then sum and stringify, repeat until single char."(if(=(lengthint-str)1)(parse-integerint-str);;tail(super-digit;;int-str(prin1-to-string(apply'+(mapcar(lambda(x)(-(char-intx)48));48ischarcodeof0(coerceint-str'list)))))));;thishelpsparsingstdin(defunsplit-string(strdelim)(let((acc'())(beg0))(loopwhile(let((end(positiondelimstr:startbeg)))(progn(push(subseqstrbegend)acc)(ifend(setqbeg(+1end))nil;breakwhile))))(nreverseacc)));;MAIN(let*((pair-n-k(split-string(read-line)#\Space))(n(carpair-n-k))(k(parse-integer(cadrpair-n-k))))(write(super-digit(prin1-to-string(*k(super-digitn))))))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Super Digit
You are viewing a single comment's thread. Return to all comments →
I tried doing this with common-lisp and realised there no string spliting function in standard lib lol.