```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 ``` ```import std.stdio; T[] permute(T)(T[] v, bool delegate(T[]) fn) { T[] ret; ret.length = v.length; void swap(int i1, int i2) { T t = v[i1]; v[i1] = v[i2]; v[i2] = t; } bool permuteStep(int n) { if(n == 1) { if(!fn(v)) { ret[] = v; return false; } else { return true; } } else { foreach(i; 0 .. n) { if(permuteStep(n - 1)) { if(n % 2 == 0) { swap(i, n - 1); } else { swap(0, n - 1); } } else { return false; } } return true; } } permuteStep!(T)(v.length); return ret; } void main() { int toDrop; long[] solutions; bool pred(int[] digits) { int[] dropped = digits[toDrop .. \$]; long number = 0; foreach(digit; dropped) { number *= 10; number += digit; } foreach(digit; dropped) { if(number % digit != 0) { return true; } } solutions ~= number; return true; } for(toDrop = 0; toDrop < 9; toDrop++) { permute!(int)([ 9, 8, 7, 6, 5, 4, 3, 2, 1 ], &pred); if(solutions.length > 0) { long maxSolution = 0; foreach(solution; solutions) { if(solution > maxSolution) { maxSolution = solution; } } writefln("%d", maxSolution); break; } } } ```