# 4-digit number, where $d_{1000} \lt d_{100} \lt d_{10}\lt d_{1}$ [closed]

I need to find all 4-digit numbers, where ones-number > tens-number > hundreds-number > thousands-number. 6789 is the highest possible such number and 1234 is the lowest. One solution is to write them all, but it is not an optimal solution.

Writing them all, gave me an answer that there are 26 numbers like these.

## closed as off-topic by Martin Ender, user9660, RunnyKine, MarcoB, m_goldbergApr 28 '16 at 13:43

• The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Apr 28 '16 at 6:11
• Is this Question about the Software Mathematica? If so please complement your Question with Code. Else Mathematics satisfies your needs better. – user9660 Apr 28 '16 at 6:12
• It was in my high school test, so computer was not allowed – Lukas Naruševičius Apr 28 '16 at 6:30
• This StackExchange site is specifically about a software system called Mathematica. One solution to this problem with it is With[{digits = Array[c, 4]}, FromDigits[digits] /. Solve[Flatten@{Less@@digits, 1 <= # <= 9 & /@ digits}, digits, Integers]]. – kirma Apr 28 '16 at 6:38
• Ask on math.stackexchange.com – Michael E2 Apr 28 '16 at 20:53

n /. Solve[
{n == th*1000 + h*100 + t*10 + u, u > t > h > th,
Thread[0 < {th, h, t, u} < 10]} // Flatten,
{th, h, t, u, n}, Integers]

(*  {1234, 1235, 1236, 1237, 1238, 1239, 1245, 1246, 1247, 1248, 1249, \
1256, 1257, 1258, 1259, 1267, 1268, 1269, 1278, 1279, 1289, 1345, \
1346, 1347, 1348, 1349, 1356, 1357, 1358, 1359, 1367, 1368, 1369, \
1378, 1379, 1389, 1456, 1457, 1458, 1459, 1467, 1468, 1469, 1478, \
1479, 1489, 1567, 1568, 1569, 1578, 1579, 1589, 1678, 1679, 1689, \
1789, 2345, 2346, 2347, 2348, 2349, 2356, 2357, 2358, 2359, 2367, \
2368, 2369, 2378, 2379, 2389, 2456, 2457, 2458, 2459, 2467, 2468, \
2469, 2478, 2479, 2489, 2567, 2568, 2569, 2578, 2579, 2589, 2678, \
2679, 2689, 2789, 3456, 3457, 3458, 3459, 3467, 3468, 3469, 3478, \
3479, 3489, 3567, 3568, 3569, 3578, 3579, 3589, 3678, 3679, 3689, \
3789, 4567, 4568, 4569, 4578, 4579, 4589, 4678, 4679, 4689, 4789, \
5678, 5679, 5689, 5789, 6789}  *)

Length[%]

(*  126  *)

• FromDigits /@ Select[Tuples[Range[9], {4}], OrderedQ[#] && DuplicateFreeQ[#] &] gives the same result, but it is perhaps more direct, and a bit faster. (+1) – MarcoB Apr 28 '16 at 16:54
• @MarcoB - I voted to reopen so that you can post your answer. – Bob Hanlon Apr 28 '16 at 17:19