32
2
Let n and b be positive integers larger than 1.
Output the distance from n to the next power of b.
For n=5 and b=3, the next power of 3 from 5 is 9 (3^2 = 9), so the output is 9 - 5 = 4.
For n=8 and b=2, the next power of 2 from 8 is 16 (2^4 = 16), so the output is 16 - 8 = 8. Note that n is a power of 2 in this example.
Testcases:
n b output
212 2 44
563 5 62
491 5 134
424 3 305
469 8 43
343 7 2058
592 7 1809
289 5 336
694 3 35
324 5 301
2 5 3
This is code-golf. Shortest answer in bytes wins. Standard loopholes apply.
4Crossed out 4 is still regular 4 ;( – Uriel – 2017-06-19T13:53:50.573
2@Uriel But
;) – HyperNeutrino – 2017-06-19T13:56:03.710tfw your initially initial thought is "oh it's
æċ!" instead of "oww this is sooo hard..." – Erik the Outgolfer – 2017-06-19T14:04:03.550Oh it might not exist in the history, but I did change from a 4 byter. It was
æċ_⁸– Jonathan Allan – 2017-06-19T14:06:55.557@JonathanAllan Since it wasn't in the history it didn't make sense and that's why I edited that out. – Erik the Outgolfer – 2017-06-19T14:11:12.233