17
Challenge:
You are given a base 10 number. For each base from 10 counting down to base 2:
- Take the original input number as a base 10 string, and remove any digits of the number which are invalid for the base.
- Interpret the resulting number string in the that base. If this gives 1 or 0, terminate the whole process.
- Output or print its largest prime factor, as decimal number.
The output can be an array of the largest prime factors.
Sample cases:
Input:
987654321
Output:
379721
10593529
1091
179
1493
293
19
7
Alternately:
[379721,10593529,1091,179,1493,293,19,7]
This prints the largest prime factors of 987654321, 876543219 = 4237411610, 76543218 = 205435310, and so on until it reaches 12, where it stops.
2I'm unclear on the process. I could probably figure it out from the example, but you should have clear instructions so this isn't needed. So we convert to a lower base, remove invalid digits, then print the largest prime factor? What base do we print this factor in? Do we then do the same process with the largest prime factor and a base one lower? Or do we do it with the number we factored? Do we start with 10 or 9? – xnor – 2016-04-10T23:47:59.560
Welcome to the site! – James – 2016-04-11T00:08:23.573
2I tried rewriting the challenge to make it clearer. I hope this is what you intended. If not, feel free to change it. – xnor – 2016-04-11T00:31:04.250
4I find the largest-prime-factor step rather tacked on to the main operation is base conversion. Many languages just do it directly with a prime-factorization built-in, and the rest basically have to do a second separate challenge. Base conversion is also built-in-or-bust. When operations come as built-ins, you expect them to be well-trodden ground for golfs, and indeed factorization and base conversion are. Still, good for a first challenge, but things to keep in mind for next time. – xnor – 2016-04-11T00:53:30.603
3Any chance this was inspired by Google Code Jam? – Mego – 2016-04-11T01:16:17.780
This is definitely inspired by Google Code Jam.
– Wildcard – 2016-04-11T19:29:06.400