There is lotto draw (5 numbers) on each row. I have formula which calculates the most frequient numbers with their number of draws. Is it possible in end result to sort same number of draws results by row value. This means that if number is drawn on top rows will have grater value than those on bottom rows. Considering number of row to be a value. How is that possible?
Formula used:
=LET(flatten, TEXTSPLIT(TEXTJOIN(";",,A1:F27),,";"), numUq, UNIQUE(flatten), matches, XMATCH(flatten,numUq),SORT(HSTACK(numUq, DROP(FREQUENCY(matches, UNIQUE(matches)),-1)),2,-1))
In the example screenshot number 35 and number 13 have equal draws count, but 13 should be before 35.
Data:
A
B
C
D
E
F
18
35
31
13
37
10
43
47
36
13
6
19
6
12
6
35
14
1
43
24
45
7
21
16
37
39
44
24
12
40
39
8
34
28
49
46
27
44
15
46
45
12
22
0
10
5
28
28
4
7
23
6
44
41
30
22
47
13
29
29
37
9
26
44
39
10
30
17
21
20
41
22
43
35
0
22
13
9
14
22
42
20
32
21
13
38
48
6
14
2
11
47
20
20
23
6
22
26
1
25
45
31
27
39
6
44
3
24
22
45
34
17
5
13
16
23
20
7
30
16
25
21
7
34
1
35
32
34
1
9
10
32
23
35
11
3
6
12
5
30
4
20
33
15
26
10
8
28
16
11
21
14
3
38
10
42
16
3
26
48
30
28
Link to file
Here it is on a bit of the data. Here I have added a third column based on the average row of each unique number and sorted first on frequency then on row average:
=LET(range,A1:F3,uniques,UNIQUE(TOCOL(range)),rows,SEQUENCE(ROWS(range)),
avrow,BYROW(uniques,LAMBDA(uniq,SUM((range=uniq)*rows/SUM(--(range=uniq))))),
freq,DROP(FREQUENCY(range,uniques),-1),
SORTBY(HSTACK(uniques,freq,avrow),freq,-1,avrow,1))
Can 6 really occur twice in the same draw? Maybe not, but it doesn't affect the answer.
EDIT
Here is a version based on your original formula:
=LET(range,A1:F27,
flatten, TEXTSPLIT(TEXTJOIN(";",,A1:F27),,";"),
numUq, UNIQUE(flatten),
rows,SEQUENCE(ROWS(range)),
matches, XMATCH(flatten,numUq),
avrow,BYROW(numUq,LAMBDA(numUq,SUM((range=--numUq)*rows/SUM(--(range=--numUq))))),
freq,DROP(FREQUENCY(matches, UNIQUE(matches)),-1),
SORTBY(HSTACK(numUq,freq,avrow),freq,-1,avrow,1))
Full Dataset
The sorting is based on number of appearances and average row, but you could use other measures like row of first appearance if you wanted to.
Different approach:
=LET(data,A1:F27,
a,TOCOL(data),
b,MMULT(--(TRANSPOSE(a)=a),SEQUENCE(COUNTA(a),,1,0)),
c,TOCOL(IF(ISNUMBER(data),MAX(ROW(data)+1)-ROW(data)^99)),
d,MMULT(--(TRANSPOSE(a)=a),c),
s,SORTBY(HSTACK(a,b),b,-1,d,1),
UNIQUE(s))
a "flattens" the data using TOCOL.
b creates a "countif" of the drawn values in a using MMULT.
c returns the maximum row value of the data + 1 minus the row value of each value found ^99.
^99 because I want the number to be higher if it would be found in the first row only versus if it was found in each row except the first.
d returns a "sumif" of the calculated row values of c against the values of a.
We than only need a and b for the list using HSTACK, but we need them sorted by the count b descending and sorted by the sumif d ascending using SORTBY.
This will sort it as you illustrated it.
If it's a tie (36 and 19 in the data) it will show the first in row first.
I have employee table, where employee id and supervisor is present. I want to find the hierarchy for the employee in five levels.
Example: Employee 1 is reported to 2, 2 reported to 4,4 reported to 17, 17 reported to 20. But we not able to find 20 supervisor so we kept the supervisor for 20 is 20 itself.
EmployeeID
SupervisiorID
1
2
2
4
8
6
9
5
6
3
5
10
4
17
3
15
10
20
15
20
17
20
16
21
15
13
14
12
13
11
Excepted output
EmployeeID
SupervisiorID_1
SupervisiorID_2
SupervisiorID_3
SupervisiorID_4
SupervisiorID_5
1
2
4
17
20
20
2
4
17
20
20
20
8
6
3
15
20
20
9
5
10
20
20
20
6
3
15
20
20
20
5
10
20
20
20
20
4
17
20
20
20
20
3
15
20
20
20
20
10
20
20
20
20
20
15
20
20
20
20
20
17
20
20
20
20
20
16
21
21
21
21
21
15
13
11
11
11
11
14
12
12
12
12
12
13
11
11
11
11
11
How can we achieve this in Spark using dataframe recursively.
Although this has been asked many times, someone here https://dwgeek.com/spark-sql-recursive-dataframe-pyspark-and-scala.html/ has solved this.
If you only have 5 levels, than it is better to use 4 joins to do the job.
In my point of view, spark doesn't support natively recursive solutions for such scenario. If you really want to do it in a recursive way, you may need to collect the data u need and do it on driver locally.
I have two dirs base and to_move. There are 10 files in base, which are named
0 1 2 3 4 5 6 7 8 9, and 3 files, 0 1 2, in to_move. What I want is to move the 3 files in to_move to base, with their names changed to 10 11 12.
Inside the dir to_move, I run the command
tmp=$(ls);for item in ${tmp[#]};do dst=$((item+10));echo $dst $item;done
what I got is
10 0
11 1
12 2
11 1
20 10
21 11
22 12
23 13
24 14
25 15
26 16
27 17
28 18
29 19
12 2
30 20
31 21
32 22
33 23
34 24
35 25
36 26
37 27
38 28
13 3
14 4
15 5
16 6
17 7
18 8
19 9
This makes no sense to me, it seems $(($item+10)) has some weird effects on $item.
Why this happens? And how can I modify the command to get this output?
10 0
11 1
12 2
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I created a lottery number generator with Python 3.7. It shows however None at the end of each try. Here's my code.
import random
def lotto_gen():
n = 1
while n < 7:
print(random.randint(1, 45), end='\t')
n += 1
return
for numbers in range(100):
print(lotto_gen())
And the result goes like this:
6 12 42 37 13 44 None
36 31 32 41 4 30 None
20 31 38 42 14 19 None
8 18 29 22 34 29 None
26 34 15 1 20 38 None
10 17 28 35 22 38 None
23 34 42 22 4 43 None
25 16 17 36 17 4 None
44 8 20 1 43 43 None
29 32 9 2 8 5 None
16 44 35 17 42 10 None
5 1 39 28 21 40 None
35 25 12 31 23 21 None
13 25 9 10 41 7 None
12 34 14 36 27 5 None
32 30 12 5 41 14 None
23 30 5 30 7 9 None
38 25 6 17 17 20 None
12 1 13 10 30 32 None
15 1 3 23 28 6 None
1 2 24 33 36 31 None
28 13 42 39 9 39 None
41 44 2 9 41 34 None
25 19 30 26 8 44 None
39 36 44 4 22 7 None
7 44 29 38 1 8 None
37 6 44 6 41 11 None
29 29 23 40 23 36 None
25 39 30 40 40 4 None
28 14 33 4 15 34 None
41 35 7 26 30 24 None
10 34 26 45 12 10 None
32 6 45 16 24 18 None
14 7 8 26 32 4 None
22 43 40 3 20 31 None
6 42 38 11 18 20 None
6 40 5 18 25 29 None
37 19 26 19 45 41 None
39 8 17 19 17 22 None
I want to remove that None bool type. Can someone tell me how can I edit my code?
Rakesh has given the correct answer, but I would like to explain why your code isn't working. The problem seems to be that for a particular iteration, your code is only able to generate 6 random numbers. Take note, that you have initialized n=1, inside the function lotto_gen() and as the condition for executing the while loop is n<7, the code inside lotto_gen() executes only 6 times.
Now the reason why you receive None at the end is because you are trying to print the value returned by lotto_gen, but take note, that the return field inside your code's function is empty, hence None is returned by the function and hence that gets printed.
So for correcting the code you only need to initialize n as n=0, and to remove the appearance of the none, don't call the function inside a print statement, and create a list which contains the 7 values of each iteration and return it. So, you'll need to modify the code in this manner:
import random
def lotto_gen():
n = 0
a=[]
while n < 7:
a.append(random.randint(1, 45))
n += 1
return a
for numbers in range(100):
print(lotto_gen())
You can use this approach too and my code will execute faster as well! :P
This is one approach.
Ex:
import random
def lotto_gen():
return "\t".join(str(random.randint(1, 45)) for _ in range(6))
for numbers in range(100):
print(lotto_gen())
I do calculations on 64 elements (for p=1:64 function end) and pull out the result values in an Excel file.
Is there any way to arrange the result values for each element row by row (the values of the first element should appear on the first row, the values of the second element should appear on the second row and so on)?
I used P=reshape(A,[],16) but Matlab pushes the values from right to the left mixing them.
For example,
If I set the loop for the calculation p=1:1 and use P=reshape(A,[],16) the result is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
If I set p=1:2 the result becomes:
for element 1: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
for element 2: 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32
(the values of element 2 are: 17 18 19 20 21 22 23 24 25 ... 32)
The result for p=1:2 should be:
for element 1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
for element 2: 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
for element 3: 33 34 35 ,etc...
Try this:
P=reshape(A,16,[])'
Is this what you need?