'Random Sorting Formula
I have a list that is made of 3’s, 6’s, and 9’s in a random order. They are then “in order” added to by 3, then 6, then 9 in a new list. The old list is never used again. Can someone help me find a formula to get the original list back?
Original_list = [3,3,6,9,6,6,3,9]
Time = [3,6,9,3,6,9,3,6]
New_list = [6,9,6,3,3,6,6,6]
New list is in random order however time is not. Old list adds to Time. I have tried making my own formulas for solving but I can’t seem to figure out how to integrate Time. Thanks!
Solution 1:[1]
You in your example we can see addition work like this:
3 + 3 = 6
3 + 6 = 9
6 + 6 = 3
6 + 9 = 6
9 + 3 = 3
9 + 6 = 6
It is not hard to gues the other 3 entries in the addition table.
So to get from the "new" list back to the "original" list, all we have to do is apply subtraction:
6 - 3 = 3
9 - 6 = 3
3 - 6 = 6
6 - 9 = 6
3 - 3 = 9
6 - 6 = 9
and so on.
Solution 2:[2]
Direct transformation might be described by formula
3 + (A[i] + 3 * i) % 9
where i is index in the list
and backward one:
3 + (C[i] + 3 - 3 * i) % 9
Python code to check:
A = [3,3,6,9,6,6,3,9]
C = [6,9,6,3,3,6,6,6]
CC = [3 + (A[i] + 3 * i)%9 for i in range(len(A))]
print(C)
print(CC)
AA = [3 + (C[i] + 3 - 3 * i)%9 for i in range(len(A))]
print(A)
print(AA)
[6, 9, 6, 3, 3, 6, 6, 6]
[6, 9, 6, 3, 3, 6, 6, 6]
[3, 3, 6, 9, 6, 6, 3, 9] #original
[3, 3, 6, 9, 6, 6, 3, 9] #result
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Beta |
| Solution 2 |
