8
3
Write a program to find a number consisting of 9 digits in which each of the digits from 1 to 9 appears only once. This number must also satisfy these divisibility requirements:
- The number should be divisible by 9.
- If the rightmost digit is removed, the remaining number should be divisible by 8.
- If the rightmost digit of the new number is removed, the remaining number should be divisible by 7.
- And so on, until there’s only one digit (which will necessarily be divisible by 1).
Credit Dávid Németh
28The first rule seems unnecessary. Any number that consists of digits 1-9 once each will always be divisible by 9. – Geobits – 2014-06-24T19:31:08.230
6
What's the code-aspect here? This sounds like it could be posted on Puzzling
– Simon Forsberg – 2014-06-24T19:32:29.0231This would be way better as a code-golf – Level River St – 2014-06-24T19:36:26.587
11Even if we’re going to call it a “standard loophole”, code golf challenges that produce a fixed output generally shorter than any code that could build it are usually not particularly interesting. – Ry- – 2014-06-24T21:23:11.677
9The problem I have with challenges like this is that the border between hardcoding and applying mathematical properties is vague. For example, the divisibility rule for 5 is that the number has to end in 0 or 5. Is restricting the choices for that digit to 0 and 5 hardcoding part of the output? It'd get even worse if we were dealing with 10-digit numbers. – user2357112 supports Monica – 2014-06-24T22:07:18.917
@user2357112 Not to mention, a bunch of mathematical operations on constants can very well get optimized out in compilers. Meaning the only difference between hard-coded and not hard-coded is optimization. So what level of optimization is allowed? I had this problem when I was writing code to convince someone of the monty hall problem. I wrote out the logic rigorously, then started optimizing redundancies. The logic ended up with literally just checking if rand(1, 3)==1 – Cruncher – 2014-06-25T14:25:08.677
@Cruncher Since the program doesn't take input the whole thing might just be constant folded to a print statement, but that is obviously not allowed to do. – Sylwester – 2014-06-26T12:38:32.003
1@Sylwester The question is essentially: "print 381654729 without printing it directly". So is "print 381654728+1" allowed? How much math must be involved before you can say you calculated it, vs. hard coding it. Hard coding the math for a constant is STILL hard coding it. Meaning that this question is literally unanswerable. – Cruncher – 2014-06-26T12:59:27.460
@Cruncher
381654728+1is not finding the value that correspond to the requirements, but I guess a solution can start off with381654728and apply the tests 0..4 (0 being all digits are unique) and then you'll find it after 2 iterations instead of 381654729 at a cost of 8 extra points. – Sylwester – 2014-06-26T13:47:48.4474@Sylwester What you've done is assume there's only 1 way to solve the problem, because you're afraid of breaking the loophole. "Loop through numbers checking requirements". This completely excludes any interesting examples. And the question is: "Which language can check these things and loop in the fewest characters". – Cruncher – 2014-06-26T14:19:14.820
@Cruncher It's like finding digits of pi. Yes, you can make a program that prints a constant but that isn't calculation is it? This is a trivial question compared to finding digits of pi but I think OP thought the number was going to be found by a golfed program and not
381654728+1since that would only work if you knew the answer was 381654729. – Sylwester – 2014-06-26T21:01:38.897@Sylwester Like-wise I find the pi-finding questions to be bad as well. – Cruncher – 2014-06-27T13:05:10.823
@Sylwester If the question asked to input the number of digits, and then apply the same logic that this question asks to print the number that satisfies it (or impossible if that's the case) that would be more interesting. Questions that cannot be hardcoded are much better than ones that have to restrict you from it. – Cruncher – 2014-06-27T13:08:32.717
@Cruncher I agree. Questions that require input makes the challenge better. – Sylwester – 2014-06-27T13:46:42.207