E
E
Elnur Tazhimbetov2017-09-20 19:50:54
Python
Elnur Tazhimbetov, 2017-09-20 19:50:54

How to shuffle digits inside a number?

A=1234
and for example there should be 24 different numbers,
1243
1342
1324
etc

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
longclaps, 2017-09-20
@tazhimbetov

itertools.permutations

D
Dmitry Alexandrov, 2017-09-21
@jamakasi666

I can assume that you were given the task to do it manually, if so, then the algorithm will be something like this in the simplest version for Java.
1) Convert number to string. Integer.toString();
2) Parse the resulting string into an array. "string".toCharArray();
3) Interfere with the array.
4) Translate the array back into a string String.valueOf("array")
5) Translate the string back into a number. Integer.parseInt("string");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question