I am trying to solve Ten True Sentences Puzzle.
Take a look at the following sentences:
- The number of times the digit 0 appears in this puzzle is _____.
- The number of times the digit 1 appears in this puzzle is _____.
- The number of times the digit 2 appears in this puzzle is _____.
- The number of times the digit 3 appears in this puzzle is _____.
- The number of times the digit 4 appears in this puzzle is _____.
- The number of times the digit 5 appears in this puzzle is _____.
- The number of times the digit 6 appears in this puzzle is _____.
- The number of times the digit 7 appears in this puzzle is _____.
- The number of times the digit 8 appears in this puzzle is _____.
- The number of times the digit 9 appears in this puzzle is _____.
Fill these sentences with digits such that all the sentences holds true.
I wrote the following code, but it didn't work.
Do[
If[Tally[Range[0, 9] ~Join~ x][[All, 2]] == x, Print@x],
{x, Tuples[Range[0, 9], 10]}] // AbsoluteTiming
How can I imporve my code?
Updated
Compile[{},
NestWhile[Join[{1, 7, 3, 2}, RandomInteger[10, 6]] &, Range[0,9],
Tally[Range[0, 9] ~Join~ #][[All, 2]] != # &],
CompilationTarget -> "C", RuntimeOptions -> "Speed"
][] // AbsoluteTiming
{1,7,3,2,1,1,1,2,1,1}
$\endgroup$