ruby use upto with range variable? - ruby

I'm trying to use a variable range with ruby, but my code does not work;
ruby -e ' input2=145..170 ; input3= input2.to_s.gsub(/(.*?)\.\.(.*?)/) { 5.upto($2.to_i) { |i| print i, " " } }; print input3' > zzmf
But I obtained 5170
This part fails:
5.upto($2.to_i) { |i| print i, " " }
I expected:
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 5170

I don't think gsub is what you need, try the match example below. [2] gets the second match from the regex /(\d+)..(\d+)/ applied to "147..170"
5.upto("147..170".match(/(\d+)\.\.(\d+)/)[2].to_i) { |i| print i, " "}
gsub is intended for string substitution.
https://ruby-doc.org/core-2.1.4/String.html#method-i-gsub

I see my code and I confuse in regular expression
I use this .*?
and the correct is this .*
(.*)/
ruby -e ' input2=145..170 ; input3= input2.to_s.gsub(/(.*?)\.\.(.*)/) { 5.upto($2.to_i) { |i| print i, " " } }; print input3' > zzmf
thanks for your responses

Related

When Cloudwatch Logs data is sent into kinesis data stream, what is its encoding format

I'm trying to write a Go program, to download data from aws kinesis data stream. I read that kinesis data stream encode the data with base64, so I need first decode with base64. However, I can't figure out what encoding was used on the data as it is passed, from cloudwatch logs to kinesis data stream.
I'm trying the different decoding method but none works. My unprocessed byte array downloaded from kinesis data stream is as the following:
[31 139 8 0 0 0 0 0 0 0 53 206 65 11 130 64 16 134 225 191 178 204 89 130 178 34 246 22 97 30 178 130 12 58 68 196 166 147 14 233 174 236 140 69 68 255 61 204 58 190 204 7 243 188 160 70 102 83 224 254 217 32 104 88 108 55 251 221 54 57 175 163 52 157 199 17 4 224 30 22 125 119 169 92 155 63 140 100 101 226 10 134 0 42 87 196 222 181 13 104 232 43 21 143 166 238 147 219 11 103 158 26 33 103 151 84 9 122 6 125 60 125 119 209 29 173 116 249 2 202 251 185 80 141 44 166 110 64 15 167 227 201 48 28 79 166 225 108 20 6 127 94 7 56 36 234 199 83 63 158 86 139 18 179 27 217 66 149 104 42 41 149 187 170 28 89 200 154 238 179 90 145 69 38 86 252 165 13 224 125 122 127 0 234 141 66 79 242 0 0 0]
Can someone give me some tips how to process this piece of data?
You can use a subscription filter with Kinesis, Lambda, or Kinesis Data Firehose. Logs that are sent to a receiving service through a subscription filter are base64 encoded and compressed with the gzip format.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html

How can I rewrite this problem so that there will be primal solution?

I am trying to solve a problem in GLPKut but it gives me this message "problem has no primal feasible solution". Below you ll find the program. I think the problem is with the variable Y because when I change it to not being binary it gives me a soulution but it's wrong. Thank you for your help in advance.
param m;#number of people
param n;#number of supplier
param f;# a cost of opening a supplier place
param u; #maximum number of people that can be supplied
param C{i in 1..m, j in 1..n}; #expenses:
var X{i in 1..m, j in 1..n}, >=0; #if the ith person is supplied by the jth supplier
var Y{j in 1..n}, binary; #if the jth supplier is open 1
s.t. F1{i in 1..m, j in 1..n}: sum{j} X[i,j]=1;
s.t. F4{j in 1..n}: sum{i in 1..m} X[i,j] <= u*Y[j];
s.t. F5{i in 1..m, j in 1..n}:X[i,j]<=Y[j];
s.t. F10{i in 1..m, j in 1..n}:X[i,j]<=1;
minimize totalcost: sum{j in 1..n}(Y[j]*f)+sum{i in 1..m}sum{j in 1..n}(C[i,j]*X[i,j]);
# minimizing the cost of opening the suppliers+expenses
solve;
printf "osszkoltseg = %.4f\n", totalcost;
data;
param m := 150; #number of people
param n := 50; #number of supplier
param f := 300; # a cost of opening a supplier place
param u := 20;
param C #C[i,j] expenses
: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 :=
1 42 43 37 13 101 103 107 11 27 74 9 99 26 63 60 70 100 71 123 24 47 87 75 131 57 172 57 52 87 80 117 103 115 131 79 39 49 97 23 29 53 68 74 87 127 93 40 121 126 76
2 33 110 96 66 46 48 96 66 86 149 66 56 87 138 15 91 45 46 116 85 118 104 102 76 98 117 46 23 36 61 62 48 94 76 154 108 28 42 52 50 128 21 127 88 72 38 111 90 71 1
3 46 75 61 95 17 19 61 73 57 114 85 21 58 103 44 56 16 13 81 60 83 69 67 47 63 88 27 32 3 26 33 19 59 47 119 73 57 13 67 55 93 16 92 53 43 9 76 55 42 36
4 106 39 45 93 105 111 43 73 55 30 83 83 56 31 124 48 114 93 41 58 35 35 37 81 41 90 93 116 103 78 77 93 45 93 23 43 113 115 87 89 43 118 12 51 95 107 42 49 86 140
5 40 117 103 77 41 37 103 73 93 156 73 63 94 145 26 98 34 53 123 92 125 111 109 65 105 106 53 30 43 68 69 53 101 65 161 115 39 31 59 57 135 28 134 95 61 39 118 97 60 10
6 128 123 129 177 65 63 59 155 139 114 167 67 140 115 126 96 66 95 49 142 119 79 91 35 109 6 109 114 79 86 49 63 51 35 107 127 139 69 149 137 127 98 92 79 39 73 126 45 40 110
7 33 72 58 82 30 32 58 60 48 111 72 28 49 100 31 53 29 8 78 47 80 66 64 60 60 101 14 19 16 23 46 32 56 60 116 70 44 26 54 42 90 17 89 50 56 22 73 52 55 39
8 96 49 55 103 95 101 33 81 65 40 93 73 66 41 114 38 104 83 31 68 45 25 27 71 35 80 83 106 93 68 67 83 35 83 33 53 103 105 77 79 53 108 18 41 85 97 52 39 76 130
9 132 127 133 181 69 67 63 159 143 118 171 71 144 119 130 100 70 99 47 146 123 83 95 39 113 4 113 118 83 90 53 67 55 39 111 131 143 73 153 141 131 102 96 83 43 77 130 49 44 114
10 21 98 84 56 56 58 84 54 74 137 54 54 75 126 5 79 55 34 104 73 106 92 90 86 86 127 34 11 42 49 72 58 82 86 142 96 18 52 40 38 116 23 115 76 82 48 99 78 81 13
11 28 55 41 77 35 37 41 55 39 94 67 33 40 83 40 36 34 9 61 42 63 49 47 65 43 106 9 32 21 14 51 37 49 65 99 53 39 31 49 37 73 34 72 33 61 27 56 55 60 56
12 74 69 75 123 35 41 27 101 85 80 113 13 86 69 72 42 44 41 47 88 65 35 37 19 55 60 55 60 33 32 7 23 25 23 85 73 85 45 95 83 73 48 58 25 25 37 72 21 16 70
13 41 36 22 68 44 46 50 46 30 75 58 42 31 64 59 17 49 28 66 33 44 30 28 74 24 115 28 51 38 23 60 46 58 74 80 34 48 50 40 28 54 53 53 30 70 42 37 64 69 75
14 50 27 17 31 81 83 87 17 7 66 21 79 6 55 68 50 80 51 103 4 35 67 55 111 37 152 37 60 67 60 97 83 95 111 71 25 57 77 31 33 45 62 54 67 107 73 28 101 106 84
15 52 71 57 101 11 13 57 79 63 110 91 17 64 99 50 52 14 19 77 66 79 65 63 41 59 82 33 38 3 22 27 13 55 41 115 69 63 15 73 61 89 22 88 49 37 7 72 51 36 40
16 45 102 88 94 26 20 88 72 78 141 84 48 79 130 43 83 17 38 108 77 110 96 94 50 90 89 38 31 28 53 54 38 86 48 146 100 56 16 66 54 120 15 119 80 44 24 103 82 45 27
17 26 85 71 75 37 39 71 53 61 124 65 35 62 113 24 66 36 21 91 60 93 79 77 67 73 108 21 12 23 36 53 39 69 67 129 83 37 33 47 35 103 4 102 63 63 29 86 65 62 26
18 25 102 88 62 50 52 88 58 78 141 58 48 79 130 11 83 49 38 108 77 110 96 94 80 90 121 38 15 36 53 66 52 86 80 146 100 24 46 44 42 120 17 119 80 76 42 103 82 75 9
19 119 114 120 168 56 60 50 146 130 105 158 58 131 106 117 87 63 86 34 133 110 70 82 30 100 15 100 105 70 77 40 54 42 42 98 118 130 64 140 128 118 89 83 70 44 64 117 36 35 101
20 45 50 44 8 108 110 114 18 34 79 6 106 33 68 55 77 107 78 130 31 54 94 82 138 64 179 64 59 94 87 124 110 122 138 84 46 44 104 24 36 58 75 81 94 134 100 47 128 133 71
21 13 90 76 60 52 54 76 46 66 129 50 50 67 118 9 71 51 26 96 65 98 84 82 82 78 123 26 3 38 41 68 54 74 82 134 88 22 48 32 30 108 19 107 68 78 44 91 72 77 21
22 7 72 58 42 70 72 76 28 48 111 32 68 49 100 23 53 69 40 92 47 80 66 64 100 60 141 26 21 56 49 86 72 84 100 116 70 12 66 14 12 90 37 89 56 96 62 73 90 95 39
23 63 14 4 52 62 68 66 30 14 53 42 58 15 42 81 29 71 50 82 17 22 46 34 90 16 131 50 73 60 39 76 62 74 90 58 12 70 72 44 46 32 75 33 46 86 64 15 80 85 97
24 65 12 6 42 70 72 76 32 12 51 32 68 11 40 83 39 73 52 92 13 20 56 44 100 26 141 52 75 62 49 86 72 84 100 56 10 72 74 46 48 30 77 43 56 96 66 13 90 95 99
25 80 13 17 51 79 85 77 47 27 36 47 69 26 25 98 40 88 67 93 28 17 57 45 101 27 142 67 90 77 52 87 73 85 101 41 9 87 89 61 63 15 92 44 57 97 81 10 91 96 114
26 17 60 46 64 48 50 54 42 36 99 54 46 37 88 35 41 47 18 70 35 68 54 52 78 48 119 4 27 34 27 64 50 62 78 104 58 26 44 36 24 78 29 77 38 74 40 61 68 73 51
27 77 30 24 48 88 90 94 44 24 39 44 86 23 38 95 57 87 64 110 25 34 74 62 118 44 159 64 87 74 67 104 90 102 118 46 26 84 86 58 60 26 89 61 74 114 80 27 108 113 111
28 46 35 41 89 45 51 29 67 51 70 79 23 52 59 64 12 54 33 45 54 39 25 23 53 21 94 33 56 43 18 39 33 37 53 75 39 53 55 61 49 49 58 48 9 49 47 38 43 48 80
29 97 92 98 146 34 32 60 124 108 113 136 36 109 102 95 65 35 64 80 111 88 68 66 22 78 37 78 83 48 55 26 32 58 10 118 96 108 38 118 106 96 67 91 52 8 42 95 54 17 79
30 98 21 35 73 97 103 45 65 45 18 65 75 44 11 116 40 106 85 61 46 15 27 29 73 33 110 85 108 95 70 69 85 53 85 23 23 105 107 79 81 23 110 12 43 87 99 22 59 78 132
31 53 54 48 24 112 114 118 22 38 63 20 110 37 62 71 81 111 82 134 35 58 98 86 142 68 183 68 63 98 91 128 114 126 142 70 50 60 108 34 40 50 79 85 98 138 104 51 132 137 87
32 45 50 44 14 108 110 114 18 34 73 10 106 33 62 61 77 107 78 130 31 54 94 82 138 64 179 64 59 94 87 124 110 122 138 78 46 50 104 24 36 52 75 81 94 134 100 47 128 133 77
33 24 63 49 73 39 41 49 51 39 102 63 37 40 91 32 44 38 9 69 38 71 57 55 69 51 110 5 24 25 18 55 41 53 69 107 61 35 35 45 33 81 26 80 41 65 31 64 59 64 48
34 55 116 102 104 40 34 102 82 92 155 94 62 93 144 53 97 31 52 122 91 124 110 108 64 104 79 52 41 42 67 68 52 100 52 160 114 66 30 76 64 134 27 133 94 50 38 117 96 59 37
35 38 83 69 87 25 27 69 65 59 122 77 29 60 111 36 64 24 19 89 58 91 77 75 55 71 96 19 24 11 34 41 27 67 55 127 81 49 21 59 47 101 8 100 61 51 17 84 63 50 28
36 106 59 65 113 105 111 43 91 75 50 103 83 76 51 124 48 114 93 23 78 55 35 37 81 45 70 93 116 103 78 77 93 45 93 43 63 113 115 87 89 63 118 28 51 95 107 62 49 86 140
37 51 46 52 100 34 40 28 78 62 81 90 12 63 70 53 23 43 22 48 65 50 36 34 42 32 83 32 45 32 9 28 22 26 42 86 50 62 44 72 60 60 47 59 20 38 36 49 32 37 69
38 86 81 87 135 79 85 17 113 97 72 125 57 98 73 98 54 88 67 3 100 77 37 49 55 67 48 67 90 77 52 51 67 19 67 65 85 97 89 107 95 85 92 50 37 69 81 84 23 60 114
39 126 49 63 97 125 131 63 93 73 14 93 103 72 21 144 68 134 113 57 74 41 55 57 101 61 106 113 136 123 98 97 113 65 113 7 51 133 135 107 109 31 138 32 71 115 127 48 69 106 160
40 35 42 28 50 62 64 68 28 18 81 40 60 19 70 53 31 61 32 84 17 50 48 36 92 30 133 22 45 48 41 78 64 76 92 86 40 42 58 22 18 60 47 59 48 88 54 43 82 87 69
41 60 17 9 57 59 65 61 35 19 56 47 53 20 45 78 24 68 47 77 22 25 41 29 85 11 126 47 70 57 34 71 57 69 85 61 15 67 69 41 43 35 72 34 41 81 61 18 75 80 94
42 33 52 38 16 96 98 102 8 28 91 8 94 29 80 43 65 95 66 118 27 60 82 70 126 52 167 52 47 82 75 112 98 110 126 96 50 32 92 12 24 70 63 69 82 122 88 53 116 121 59
43 124 47 61 95 123 129 61 91 71 32 91 101 70 33 142 66 132 111 41 72 39 53 55 99 59 88 111 134 121 96 95 111 63 111 25 49 131 133 105 107 45 136 30 69 113 125 46 67 104 158
44 33 90 76 82 30 32 76 60 66 129 72 36 67 118 31 71 29 26 96 65 98 84 82 60 78 101 26 19 16 41 46 32 74 60 134 88 44 26 54 42 108 3 107 68 56 22 91 70 55 21
45 88 81 87 135 87 93 25 113 97 72 125 65 98 73 106 54 96 75 5 100 77 37 49 63 67 48 75 98 85 60 59 75 27 75 65 85 97 97 107 95 85 100 50 37 77 89 84 31 68 122
46 75 70 76 124 56 62 6 102 86 61 114 34 87 62 75 43 65 44 26 89 66 26 38 32 56 59 56 67 54 33 28 44 4 44 64 74 86 66 96 84 74 69 39 26 46 58 73 8 37 91
47 79 86 80 128 16 14 72 106 90 125 118 32 91 114 77 67 17 46 92 93 94 80 78 34 74 55 60 65 30 37 38 22 70 22 130 84 90 20 100 88 104 49 103 64 20 24 87 66 29 61
48 63 20 14 34 78 80 84 30 10 53 30 76 9 42 81 47 77 50 100 11 24 64 52 108 34 149 50 73 64 57 94 80 92 108 58 16 70 74 44 46 32 75 51 64 104 70 17 98 103 97
49 34 111 97 77 35 37 97 67 87 150 67 57 88 139 26 92 34 47 117 86 119 105 103 65 99 106 47 24 37 62 63 47 95 65 155 109 39 31 53 51 129 22 128 89 61 33 112 91 60 10
50 32 61 47 17 95 97 101 17 37 100 17 93 38 89 34 64 94 65 117 36 69 81 69 125 51 166 51 46 81 74 111 97 109 125 105 59 23 91 11 23 79 62 78 81 121 87 62 115 120 50
51 58 33 39 87 57 63 31 65 49 58 77 35 50 47 76 6 66 45 47 52 29 13 11 55 19 96 45 68 55 30 41 45 39 55 63 37 65 67 59 47 37 70 36 11 51 59 36 45 50 92
52 97 64 70 118 96 102 34 96 80 55 108 74 81 56 115 39 105 84 16 83 60 26 32 72 50 65 84 107 94 69 68 84 36 84 48 68 104 106 90 80 68 109 33 42 86 98 67 40 77 131
53 83 78 84 132 20 22 46 110 94 99 122 22 95 88 81 51 25 50 66 97 74 54 52 10 64 51 64 69 34 41 12 18 44 10 104 82 94 26 104 92 82 53 77 38 6 28 81 40 5 65
54 51 128 114 92 52 46 114 84 104 167 84 74 105 156 41 109 43 64 134 103 136 122 120 76 116 91 64 41 54 79 80 64 112 64 172 126 54 42 70 68 146 39 145 106 62 50 129 108 71 25
55 52 33 27 23 91 93 97 19 17 64 19 89 16 53 70 60 90 61 113 14 37 77 65 121 47 162 47 62 77 70 107 93 105 121 69 29 59 87 33 35 43 64 64 77 117 83 30 111 116 86
56 103 98 104 152 48 54 34 130 114 89 142 42 115 90 101 71 57 70 34 117 94 54 66 24 84 31 84 89 54 61 24 38 26 36 82 102 114 58 124 112 102 73 67 54 38 50 101 20 29 85
57 56 49 43 27 107 109 113 23 33 60 23 105 32 57 74 76 106 77 129 30 53 93 81 137 63 178 63 66 93 86 123 109 121 137 65 45 63 103 37 39 45 74 80 93 133 99 46 127 132 90
58 38 39 25 45 67 69 73 23 15 78 35 65 16 67 56 36 66 37 89 14 47 53 41 97 27 138 25 48 53 46 83 69 81 97 83 37 45 63 19 21 57 50 56 53 93 59 40 87 92 72
59 31 60 46 80 32 34 46 58 42 99 70 30 43 88 35 41 31 4 66 45 68 54 52 62 48 103 12 27 18 11 48 34 46 62 104 58 42 28 52 40 78 29 77 38 58 24 61 52 57 51
60 12 89 75 53 59 61 75 45 65 128 45 57 66 117 6 70 58 29 95 64 97 83 81 89 77 130 25 10 45 40 75 61 73 89 133 87 15 55 31 29 107 26 106 67 85 51 90 79 84 22
61 54 23 9 53 59 61 65 31 15 62 43 57 16 51 72 28 62 41 81 18 31 45 33 89 15 130 41 64 51 38 75 61 73 89 67 21 61 63 35 37 41 66 40 45 85 55 24 79 84 88
62 57 40 46 94 56 62 24 72 56 59 84 34 57 48 75 13 65 44 40 59 36 14 12 48 26 89 44 67 54 29 34 44 32 48 64 44 64 66 66 54 44 69 37 4 46 58 43 38 43 91
63 23 68 54 72 40 42 54 50 44 107 62 38 45 96 27 49 39 10 74 43 76 62 60 70 56 111 4 19 26 19 56 42 54 70 112 66 34 36 44 32 86 21 85 46 66 32 69 60 65 43
64 45 122 108 90 46 40 108 78 98 161 80 68 99 150 39 103 37 58 128 97 130 116 114 70 110 93 58 35 48 73 74 58 106 58 166 120 52 36 64 62 140 33 139 100 56 44 123 102 65 23
65 70 65 71 119 13 19 49 97 81 102 109 9 82 91 68 44 22 37 69 84 71 57 55 23 51 64 51 56 21 28 15 5 47 23 107 69 81 23 91 79 81 40 80 41 19 15 68 43 18 52
66 87 12 24 58 86 92 76 54 34 29 54 68 33 20 105 39 95 74 92 35 16 56 44 100 26 141 74 97 84 59 86 74 84 100 34 12 94 96 68 70 8 99 43 56 96 88 9 90 95 121
67 46 119 105 95 43 37 105 75 95 158 85 65 96 147 44 100 34 55 125 94 127 113 111 67 107 88 55 32 45 70 71 55 103 55 163 117 57 33 67 59 137 30 136 97 53 41 120 99 62 28
68 50 29 35 83 49 55 35 61 45 66 73 27 46 55 68 8 58 37 51 48 35 21 19 59 15 100 37 60 47 22 45 37 43 59 71 33 57 59 55 43 45 62 44 15 55 51 32 49 54 84
69 42 53 41 7 105 107 111 15 31 92 9 103 30 81 44 74 104 75 127 28 61 91 79 135 61 176 61 56 91 84 121 107 119 135 97 51 31 101 21 33 71 72 78 91 131 97 54 125 130 60
70 71 66 72 120 54 60 8 98 82 61 110 32 83 58 73 39 63 42 28 85 62 22 34 30 52 63 52 65 52 29 26 42 6 42 66 70 82 64 92 80 70 67 39 22 44 56 69 12 35 89
71 53 28 22 26 86 88 92 20 12 63 20 84 11 52 71 55 85 56 108 9 32 72 60 116 42 157 42 63 72 65 102 88 100 116 68 24 60 82 34 36 42 65 59 72 112 78 25 106 111 87
72 51 64 52 100 12 18 50 78 62 103 90 10 63 92 49 45 21 18 70 65 72 58 56 42 52 83 32 37 10 15 28 14 48 42 108 62 62 22 72 60 82 25 81 42 38 14 65 44 37 47
73 37 114 100 84 38 32 100 70 90 153 74 60 91 142 33 95 29 50 120 89 122 108 106 62 102 99 50 27 40 65 66 50 98 58 158 112 46 28 56 54 132 25 131 92 54 36 115 94 57 17
74 112 107 113 161 49 47 43 139 123 98 151 51 124 99 110 80 50 79 57 126 103 63 75 19 93 22 93 98 63 70 33 47 35 19 95 111 123 53 133 121 111 82 76 63 23 57 110 31 24 94
75 87 70 76 124 86 92 24 102 86 61 114 64 87 62 105 43 95 74 10 89 66 26 38 62 56 59 74 97 84 59 58 74 26 74 54 74 94 96 96 84 74 99 39 32 76 88 73 30 67 121
76 50 95 81 99 19 15 81 77 71 134 89 41 72 123 48 76 12 31 101 70 103 89 87 43 83 84 31 36 21 46 47 31 79 43 139 93 61 9 71 59 113 20 112 73 39 17 96 75 38 32
77 50 55 49 19 113 115 119 23 39 68 15 111 38 63 66 82 112 83 135 36 59 99 87 143 69 184 69 64 99 92 129 115 127 143 73 51 55 109 29 41 51 80 86 99 139 105 52 133 138 82
78 109 32 46 80 108 114 46 76 56 17 76 86 55 18 127 51 117 96 54 57 24 38 40 84 44 103 96 119 106 81 80 96 48 96 12 34 116 118 90 92 30 121 15 54 98 110 31 52 89 143
79 107 102 108 156 48 54 38 134 118 93 146 46 119 94 105 75 57 74 34 121 98 58 70 24 88 27 88 93 58 65 28 42 30 36 86 106 118 58 128 116 106 77 71 58 38 52 105 24 29 89
80 27 54 40 22 90 92 96 10 30 93 12 88 31 82 41 59 89 60 112 29 62 76 64 120 46 161 46 41 76 69 106 92 104 120 98 52 30 86 6 18 72 57 71 76 116 82 55 110 115 57
81 71 66 72 120 64 70 2 98 82 57 110 42 83 58 83 39 73 52 18 85 62 22 34 40 52 63 52 75 62 37 36 52 6 52 56 70 82 74 92 80 70 77 35 22 54 66 69 12 45 99
82 24 75 61 73 39 41 61 51 51 114 63 37 52 103 22 56 38 11 81 50 83 69 67 69 63 110 11 12 25 26 55 41 59 69 119 73 35 35 45 33 93 14 92 53 65 31 76 59 64 36
83 91 86 92 140 86 92 24 118 102 77 130 64 103 78 105 59 95 74 6 105 82 42 54 62 72 47 74 97 84 59 58 74 26 74 70 90 102 96 112 100 90 99 55 42 76 88 89 30 67 121
84 59 64 58 10 122 124 128 32 48 77 20 120 47 72 61 91 121 92 144 45 68 108 96 152 78 193 78 73 108 101 138 124 136 152 82 60 48 118 38 50 60 89 95 108 148 114 61 142 147 77
85 104 99 105 153 47 53 35 131 115 90 143 43 116 91 102 72 56 71 35 118 95 55 67 23 85 30 85 90 55 62 25 39 27 35 83 103 115 57 125 113 103 74 68 55 37 49 102 21 28 86
86 64 57 63 111 63 69 7 89 73 52 101 41 74 49 82 30 72 51 23 76 53 13 25 39 43 72 51 74 61 36 35 51 15 51 57 61 73 73 83 71 61 76 30 13 53 65 60 21 44 98
87 116 111 117 165 53 51 47 143 127 102 155 55 128 103 114 84 54 83 55 130 107 67 79 23 97 18 97 102 67 74 37 51 39 23 95 115 127 57 137 125 115 86 80 67 27 61 114 33 28 98
88 108 33 45 87 107 113 45 75 55 24 77 85 54 25 126 50 116 95 47 56 29 37 39 83 43 96 95 118 105 80 79 95 47 95 17 37 115 117 89 91 37 120 14 53 97 109 36 51 88 142
89 38 39 25 31 81 83 87 9 15 78 21 79 16 67 56 50 80 51 103 14 47 67 55 111 37 152 37 48 67 60 97 83 95 111 83 37 45 77 19 21 57 50 56 67 107 73 40 101 106 72
90 72 41 47 95 71 77 23 73 57 44 85 49 58 33 90 14 80 59 39 60 37 3 9 47 27 88 59 82 69 44 43 59 31 59 49 45 79 81 67 55 45 84 22 17 61 73 44 37 52 106
91 50 43 49 97 49 55 21 75 59 66 87 27 60 55 68 16 58 37 37 62 39 21 19 45 29 86 37 60 47 22 31 37 29 45 71 47 59 59 69 57 47 62 44 5 41 51 46 35 40 84
92 71 8 8 46 70 76 72 38 18 45 38 64 17 34 89 35 79 58 88 19 14 52 40 96 22 137 58 81 68 45 82 68 80 96 50 4 78 80 52 54 24 83 39 52 92 72 7 86 91 105
93 50 45 51 99 37 43 25 77 61 78 89 15 62 67 56 20 46 25 45 64 47 33 31 43 31 84 31 48 35 10 29 25 27 43 83 49 61 47 71 59 57 50 56 17 39 39 48 33 38 72
94 132 127 133 181 69 67 63 159 143 118 171 71 144 119 130 100 70 99 47 146 123 83 95 39 113 2 113 118 83 90 53 67 55 39 111 131 143 73 153 141 131 102 96 83 43 77 130 49 44 114
95 78 9 15 49 77 83 73 45 25 38 45 65 24 27 96 36 86 65 89 26 13 53 41 97 23 138 65 88 75 50 83 69 81 97 43 5 85 87 59 61 17 90 40 53 93 79 6 87 92 112
96 37 62 48 86 26 28 48 64 48 101 76 24 49 90 35 43 25 4 68 51 70 56 54 56 50 97 18 25 12 13 42 28 46 56 106 60 48 24 58 46 80 27 79 40 52 18 63 46 51 49
97 34 47 35 83 29 35 35 61 45 86 73 27 46 75 48 28 38 17 53 48 55 41 39 59 35 100 17 40 27 8 45 31 43 59 91 45 45 39 55 43 65 42 64 25 55 31 48 49 54 64
98 34 109 95 83 33 31 95 65 85 148 73 55 86 137 32 90 28 45 115 84 117 103 101 59 97 100 45 22 35 60 61 45 93 59 153 107 45 25 55 49 127 20 126 87 55 31 110 89 54 16
99 12 89 75 41 71 73 77 45 65 128 45 69 66 117 10 70 70 41 95 64 97 83 81 101 77 142 27 22 57 50 87 73 85 101 133 87 5 67 31 29 107 38 106 67 97 63 90 91 96 26
100 52 25 17 65 51 57 53 43 27 64 55 45 28 53 70 16 60 39 69 30 33 33 21 77 13 118 39 62 49 26 63 49 61 77 69 23 59 61 37 35 43 64 42 33 73 53 26 67 72 86
101 112 107 113 161 49 47 43 139 123 98 151 51 124 99 110 80 50 79 53 126 103 63 75 19 93 22 93 98 63 70 33 47 35 19 91 111 123 53 133 121 111 82 76 63 23 57 110 29 24 94
102 62 101 87 111 25 19 87 89 77 140 101 47 78 129 60 82 16 37 107 76 109 95 93 49 89 72 43 48 27 52 53 37 85 37 145 99 73 15 83 71 119 32 118 79 35 23 102 81 44 44
103 84 79 85 133 51 57 15 111 95 70 123 29 96 71 82 52 60 51 31 98 75 35 47 27 65 50 65 70 49 42 23 39 9 39 69 83 95 61 105 93 83 64 48 35 41 53 82 5 32 86
104 93 32 38 86 92 98 32 64 48 23 76 70 49 24 111 35 101 80 48 51 28 22 24 68 28 97 80 103 90 65 64 80 40 80 28 36 100 102 74 76 36 105 1 38 82 94 35 46 73 127
105 34 59 45 15 97 99 103 15 35 98 15 95 36 87 36 66 96 67 119 34 67 83 71 127 53 168 53 48 83 76 113 99 111 127 103 57 25 93 13 25 77 64 76 83 123 89 60 117 122 52
106 40 117 103 69 43 45 103 73 93 156 73 63 94 145 22 98 42 53 123 92 125 111 109 73 105 114 53 30 43 68 69 53 101 73 161 115 33 39 59 57 135 28 134 95 69 39 118 97 68 6
107 105 100 106 154 42 40 46 132 116 99 144 44 117 92 103 73 43 72 66 119 96 56 68 12 86 29 86 91 56 63 26 40 44 12 104 104 116 46 126 114 104 75 77 56 16 50 103 40 17 87
108 48 49 49 97 27 33 35 75 59 88 87 13 60 77 46 30 36 15 55 62 57 43 41 45 37 86 29 38 25 6 31 17 33 45 93 47 59 37 69 57 67 40 66 27 41 29 50 35 40 62
109 45 60 46 94 18 22 46 72 56 99 84 16 57 88 43 41 25 12 66 59 68 54 52 48 48 89 26 31 14 11 34 20 44 48 104 58 56 26 66 54 78 29 77 38 44 18 61 40 43 51
110 57 52 58 106 56 62 12 84 68 59 96 34 69 48 75 25 65 44 28 71 48 14 20 36 38 77 44 67 54 29 28 44 20 44 64 56 68 66 78 66 56 69 37 8 46 58 55 26 37 91
111 119 48 56 102 118 124 56 86 66 39 92 96 65 40 137 61 127 106 36 67 44 48 50 94 54 81 106 129 116 91 90 106 58 106 32 52 126 128 100 102 52 131 25 64 108 120 51 62 99 153
112 65 26 32 80 64 70 38 58 42 51 70 42 43 40 83 7 73 52 54 45 22 18 6 62 12 103 52 75 62 37 48 52 46 62 56 30 72 74 52 48 30 77 29 18 58 66 29 52 57 99
113 125 120 126 174 62 60 56 152 136 111 164 64 137 112 123 93 63 92 40 139 116 76 88 32 106 9 106 111 76 83 46 60 48 36 104 124 136 66 146 134 124 95 89 76 38 70 123 42 37 107
114 57 98 84 106 22 16 84 84 74 137 96 44 75 126 55 79 13 34 104 73 106 92 90 46 86 77 38 43 24 49 50 34 82 36 142 96 68 12 78 66 116 27 115 76 32 20 99 78 41 39
115 48 43 49 97 43 49 21 75 59 72 87 21 60 61 62 16 52 31 39 62 41 27 25 45 29 86 31 54 41 16 31 31 29 45 77 47 59 53 69 57 51 56 50 11 41 45 46 35 40 78
116 28 49 35 49 63 65 69 27 25 88 39 61 26 77 46 32 62 33 85 24 57 49 41 93 37 134 19 38 49 42 79 65 77 93 93 47 35 59 21 11 67 40 66 49 89 55 50 83 88 62
117 27 50 36 66 46 48 52 44 28 89 56 44 29 78 45 31 45 16 68 31 58 44 42 76 38 117 14 37 32 25 62 48 60 76 94 48 34 42 38 26 68 39 67 32 72 38 51 66 71 61
118 124 119 125 173 61 59 55 151 135 110 163 63 136 111 122 92 62 91 39 138 115 75 87 31 105 14 105 110 75 82 45 59 47 41 103 123 135 65 145 133 123 94 88 75 43 69 122 41 36 106
119 113 36 50 84 112 118 50 80 60 9 80 90 59 10 131 55 121 100 62 61 28 42 44 88 48 111 100 123 110 85 84 100 54 100 8 38 120 122 94 96 22 125 19 58 102 114 35 60 93 147
120 13 90 76 42 70 72 76 46 66 129 46 68 67 118 9 71 69 40 96 65 98 84 82 100 78 141 26 21 56 49 86 72 84 100 134 88 6 66 32 30 108 37 107 68 96 62 91 90 95 25
121 86 9 23 57 85 91 67 53 33 30 53 63 32 19 104 30 94 73 83 34 7 47 35 91 21 132 73 96 83 58 77 73 75 91 35 11 93 95 67 69 9 98 34 47 87 87 8 81 86 120
122 93 88 94 142 36 42 26 120 104 79 132 32 105 80 91 61 45 60 46 107 84 44 56 12 74 41 74 79 44 51 14 28 24 24 84 92 104 46 114 102 92 63 57 44 26 38 91 20 17 75
123 77 12 18 66 76 82 52 44 28 39 56 54 29 28 95 19 85 64 68 31 8 32 20 76 12 117 64 87 74 49 62 64 60 76 44 16 84 86 58 60 18 89 19 32 72 78 15 66 71 111
124 15 62 48 60 52 54 58 38 38 101 50 50 39 90 33 43 51 22 74 37 70 56 54 82 50 123 8 25 38 31 68 54 66 82 106 60 22 48 32 20 80 27 79 40 78 44 63 72 77 49
125 70 31 37 85 69 75 33 63 47 46 75 47 48 35 88 12 78 57 49 50 27 13 1 57 17 98 57 80 67 42 43 57 41 57 51 35 77 79 57 53 35 82 24 15 59 71 34 47 52 104
126 26 53 39 23 89 91 95 9 29 92 13 87 30 81 42 58 88 59 111 28 61 75 63 119 45 160 45 40 75 68 105 91 103 119 97 51 31 85 5 17 71 56 70 75 115 81 54 109 114 58
127 52 47 53 101 37 43 25 79 63 78 91 15 64 67 56 20 46 25 45 66 47 33 31 41 33 82 33 48 35 10 27 25 25 41 83 51 63 47 73 61 57 50 56 17 37 39 50 31 36 72
128 86 81 87 135 63 69 17 113 97 72 125 41 98 73 84 54 72 53 19 100 77 37 49 39 67 48 67 74 61 44 35 51 9 51 65 85 97 73 107 95 85 76 50 37 53 65 84 7 44 98
129 40 37 25 73 39 45 45 51 35 76 63 37 36 65 58 18 48 27 61 38 45 31 29 69 25 110 27 50 37 18 55 41 53 69 81 35 47 49 45 33 55 52 54 25 65 41 38 59 64 74
130 26 53 39 75 37 39 43 53 37 92 65 35 38 81 42 34 36 11 59 40 61 47 45 67 41 108 11 34 23 16 53 39 51 67 97 51 37 33 47 35 71 36 70 31 63 29 54 57 62 58
131 108 31 45 83 107 113 45 75 55 20 75 85 54 21 126 50 116 95 51 56 25 37 39 83 43 100 95 118 105 80 79 95 47 95 13 33 115 117 89 91 33 120 14 53 97 109 32 51 88 142
132 65 30 24 36 88 90 94 32 14 51 32 86 13 40 83 57 87 58 110 13 34 74 62 118 44 159 52 75 74 67 104 90 102 118 56 26 72 84 46 48 30 77 61 74 114 80 27 108 113 99
133 12 65 51 57 55 57 61 35 41 104 47 53 42 93 30 46 54 25 77 40 73 59 57 85 53 126 11 22 41 34 71 57 69 85 109 63 19 51 29 17 83 24 82 43 81 47 66 75 80 46
134 60 27 33 81 59 65 37 59 43 56 71 37 44 45 78 2 68 47 53 46 25 17 9 61 13 102 47 70 57 32 47 47 45 61 61 31 67 69 53 43 35 72 34 17 57 61 30 51 56 94
135 52 25 11 53 59 61 65 31 15 64 43 57 16 53 70 28 60 39 81 18 33 45 33 89 15 130 39 62 49 38 75 61 73 89 69 23 59 61 33 35 43 64 42 45 85 53 26 79 84 86
136 65 60 66 114 16 22 46 92 76 99 104 6 77 88 63 41 25 32 66 79 68 54 52 28 48 69 46 51 16 23 14 4 44 28 104 64 76 26 86 74 78 35 77 38 24 18 63 40 23 51
137 115 38 52 86 114 120 56 82 62 1 82 92 61 10 133 57 123 102 72 63 30 44 46 90 50 121 102 125 112 87 86 102 64 102 8 40 122 124 96 98 20 127 23 60 104 116 37 70 95 149
138 64 59 65 113 55 61 7 91 75 60 103 33 76 51 74 32 64 43 27 78 55 15 27 31 45 70 45 66 53 28 27 43 13 43 65 63 75 65 85 73 63 68 38 15 45 57 62 19 36 90
139 43 48 42 10 106 108 112 16 32 77 6 104 31 66 57 75 105 76 128 29 52 92 80 136 62 177 62 57 92 85 122 108 120 136 82 44 46 102 22 34 56 73 79 92 132 98 45 126 131 73
140 45 50 44 6 108 110 114 18 34 81 6 106 33 70 53 77 107 78 130 31 54 94 82 138 64 179 64 59 94 87 124 110 122 138 86 46 42 104 24 36 60 75 81 94 134 100 47 128 133 69
141 96 91 97 145 71 77 27 123 107 82 135 49 108 83 94 64 80 63 11 110 87 47 59 47 77 38 77 82 69 54 43 59 19 59 75 95 107 81 117 105 95 84 60 47 61 73 94 15 52 106
142 75 80 76 124 12 10 66 102 86 119 114 26 87 108 73 61 13 42 86 89 88 74 72 28 68 59 56 61 26 33 32 16 64 18 124 78 86 16 96 84 98 45 97 58 14 20 81 60 23 57
143 41 54 42 90 22 28 40 68 52 93 80 20 53 82 41 35 31 10 60 55 62 48 46 52 42 93 22 33 20 5 38 24 38 52 98 52 52 32 62 50 72 35 71 32 48 24 55 42 47 57
144 14 83 69 35 77 79 83 39 59 122 39 75 60 111 16 64 76 47 99 58 91 77 75 107 71 148 33 28 63 56 93 79 91 107 127 81 3 73 25 23 101 44 100 63 103 69 84 97 102 32
145 7 84 70 42 70 72 76 40 60 123 40 68 61 112 11 65 69 40 92 59 92 78 76 100 72 141 26 21 56 49 86 72 84 100 128 82 4 66 26 24 102 37 101 62 96 62 85 90 95 27
146 111 34 48 82 110 116 60 78 58 5 78 88 57 6 129 53 119 98 76 59 26 40 42 86 46 125 98 121 108 83 82 98 68 98 12 36 118 120 92 94 16 123 27 56 100 112 33 74 91 145
147 97 36 42 90 96 102 34 68 52 27 80 74 53 28 115 39 105 84 44 55 32 26 28 72 32 93 84 107 94 69 68 84 36 84 24 40 104 106 78 80 40 109 5 42 86 98 39 42 77 131
148 55 60 54 18 118 120 124 28 44 69 16 116 43 68 65 87 117 88 140 41 64 104 92 148 74 189 74 69 104 97 134 120 132 148 76 56 54 114 34 46 56 85 91 104 144 110 57 138 143 81
149 114 109 115 163 51 49 45 141 125 100 153 53 126 101 112 82 52 81 47 128 105 65 77 21 95 20 95 100 65 72 35 49 37 23 93 113 125 55 135 123 113 84 78 65 25 59 112 31 26 96
150 24 53 39 35 77 79 83 13 29 92 25 75 30 81 42 46 76 47 99 28 61 63 51 107 41 148 33 34 63 56 93 79 91 107 97 51 31 73 7 7 71 44 70 63 103 69 54 97 102 58;
end;
As mentioned in the comments: F1{i in 1..m, j in 1..n}: sum{j} X[i,j]=1; does not look right.
A constraint like:
F1{i in 1..m, j in 1..n}: X[i,j]=1;
will fix all X variables to one (making the problem infeasible).
The constraint
F1{i in 1..m, j in 1..n}: sum{j} X[i,j]=1;
is really not changing much (just adds a useless sum): it still fixes all X variables to one. You can verify this by generating and inspecting an LP file. It should show:
Subject To
F1(1,1): + X(1,1) = 1
F1(1,2): + X(1,2) = 1
F1(1,3): + X(1,3) = 1
F1(1,4): + X(1,4) = 1
. . .
Generating the LP file is a useful debugging tool.

Create a file according to sort contend

I have a list of more than 100000 records.
per example the values from 21 to 84 are continuous, then it will be 21-84 but if it is not continuous as the case 84 87, then it need to be 84,87 separated by ,
at beginning of each line will be the value 11111.
The values from the list will be in the column range of 21 to 80 with, at last.
The length of each row need to be maximum 80.
here is the input file.
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
87
85
86
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
108
111
109
112
110
113
115
114
117
116
118
124
125
120
122
123
126
132
127
133
128
130
131
135
136
137
138
139
140
141
142
143
144
145
146
148
147
149
150
151
152
153
154
155
156
158
157
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
184
183
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
214
here in the output file desired.
111111 21-84,87,85-86,88-106,108,111,109,112,110,113,115,114,117,
111111 116,118,124-125,120,122-123,126,132,127,133,128,130-131,
111111 135-146,148,147,149-156,158,157,159-182,184,183,185-212,214,
thanks in advance
Presented without explanation: check the man pages for the commands used and come back with questions:
awk '
function printrange() { print start (start == last ? "" : "-" last) }
NR == 1 {start=last=$1; next}
$1 == last+1 {last=$1; next}
{printrange(); start=last=$1}
END {printrange()}
' file | paste -sd" " | fold -sw 60 | tr ' ' ',' | sed 's/^/111111 /'
111111 21-84,87,85-86,88-106,108,111,109,112,110,113,115,114,117,
111111 116,118,124-125,120,122-123,126,132,127,133,128,130-131,
111111 135-146,148,147,149-156,158,157,159-182,184,183,185-212,214

Sort by biggest difference between different values on the same line

I have a data set that I need to do some specific sorting on. Here is a sample:
43 37 1512 1591 59 2819 97 1546 1435
43 37 1512 1591 59 2819 98 331 1539
43 37 1512 1591 59 2819 99 67 633
43 67 2772 2881 37 10189 51 2000 806
43 67 2772 2881 37 10189 52 228 1315
43 67 2772 2881 37 10189 61 2657 718
43 67 2772 2881 37 10189 62 893 1818
43 67 2772 2881 37 10189 63 1553 1293
43 67 2772 2881 47 8375 74 95 185
43 67 2772 2881 47 8375 75 1919 862
43 67 2772 2881 47 8375 79 1425 651
31 61 1800 1891 47 3983 86 137 300
31 61 1800 1891 47 3983 87 67 470
31 61 1800 1891 47 3983 88 1711 285
For each line, I need to sort the values from smallest to longest, and then find out the difference between each value. I then need to find the smallest difference between the sorted values, and append that number to the end of the line. Lastly (and here is the tricky part), I need to display all the lines in numerically sorted of the 'smallest difference' column, but the other values have to be in their original order.
For example, using the last line of the data set, the script would have to do the following:
Start:
31 61 1800 1891 47 3983 88 1711 285
Sorted:
31 47 61 88 285 1711 1800 1891 3983
Differences between each#
. 16 14 27 197 1426 89 91 2092
Smallest Difference:
14
Prepend smallest difference to ORIGINAL LINE in its own column:
14 31 61 1800 1891 47 3983 88 1711 285
And lastly, sort all the lines based on the newly added 'smallest difference' column. I don't care about the amount of white space between the columns, that can fluctuate as needed to make the script simpler.
This was a bit beyond my bash scripting ability, so I figured I'd turn to the Internet for help. Any assistance would be greatly appreciated.
I'd go with Perl for this:
perl -lane '
BEGIN { $,=" "; sub numeric {$a <=> $b} }
#sorted = sort numeric #F;
#diffs = map {$sorted[$_] - $sorted[$_-1]} 1..$#sorted;
$min_diff = ( sort numeric #diffs )[0];
print $min_diff, #F
' filename | sort -n
4 43 67 2772 2881 37 10189 63 1553 1293
4 43 67 2772 2881 47 8375 74 95 185
4 43 67 2772 2881 47 8375 75 1919 862
4 43 67 2772 2881 47 8375 79 1425 651
5 43 67 2772 2881 37 10189 62 893 1818
6 31 61 1800 1891 47 3983 87 67 470
6 43 37 1512 1591 59 2819 97 1546 1435
6 43 37 1512 1591 59 2819 98 331 1539
6 43 37 1512 1591 59 2819 99 67 633
6 43 67 2772 2881 37 10189 51 2000 806
6 43 67 2772 2881 37 10189 52 228 1315
6 43 67 2772 2881 37 10189 61 2657 718
14 31 61 1800 1891 47 3983 86 137 300
14 31 61 1800 1891 47 3983 88 1711 285
Ruby is even shorter:
ruby -ane '
min_diff = $F.map(&:to_i).sort.each_cons(2).map {|a,b| b-a}.sort.min
puts [min_diff, $F].join " "
'
A bit of a mouthful, but I think this is more or less what you need:
#!/bin/bash
mapfile -t a < "$1" # read file into an array
for i in ${!a[#]}; do # loop over the array
p=0 # "previous" number
# convert line of numbers to one number per line, then sort and loop
< <(for n in $(sort -n <<< "${a[i]//[[:blank:]]/$'\n'}" ); do
if [ $p -gt 0 ]; then # if not 1st number
echo $((n-p)) # calculate difference
fi
p=$n # save number for next calc
done | sort -n) read d _ # get smallest diff from process substitution
echo "$d ${a[i]}" # paste difference at the start of the line
done | sort -n # sort by smallest difference
Save as a script, chmod +x and run:
$ ./nsort.sh input.txt
4 43 67 2772 2881 37 10189 63 1553 1293
4 43 67 2772 2881 47 8375 74 95 185
4 43 67 2772 2881 47 8375 75 1919 862
4 43 67 2772 2881 47 8375 79 1425 651
5 43 67 2772 2881 37 10189 62 893 1818
6 31 61 1800 1891 47 3983 87 67 470
6 43 37 1512 1591 59 2819 97 1546 1435
6 43 37 1512 1591 59 2819 98 331 1539
6 43 37 1512 1591 59 2819 99 67 633
6 43 67 2772 2881 37 10189 51 2000 806
6 43 67 2772 2881 37 10189 52 228 1315
6 43 67 2772 2881 37 10189 61 2657 718
14 31 61 1800 1891 47 3983 86 137 300
14 31 61 1800 1891 47 3983 88 1711 285
$
Note mapfile is new to bash, since version 4.0 If you have an older version, you'd need a while read loop to read the file into an array.
Normally you should give some idea of what you have tried and not count on the SO community to write your scripts for you in their entirety.
Using Gnu Awk version 4:
awk -f a.awk file
where a.awk is:
BEGIN {
PROCINFO["sorted_in"]="#val_num_asc"
}
{
for (i=1; i<=NF; i++)
a[i]=$i
j=0;
for (i in a) {
j++;
if (j>1) {
d=a[i]-prev;
if (j==2) mind=d;
else if (d<mind) mind=d;
}
prev=a[i]
}
b[FNR]=(mind OFS $0)
c[FNR]=mind
}
END {
for (i in c)
print b[i]
}
Output:
4 43 67 2772 2881 37 10189 63 1553 1293
4 43 67 2772 2881 47 8375 74 95 185
4 43 67 2772 2881 47 8375 75 1919 862
4 43 67 2772 2881 47 8375 79 1425 651
5 43 67 2772 2881 37 10189 62 893 1818
6 43 37 1512 1591 59 2819 97 1546 1435
6 43 37 1512 1591 59 2819 98 331 1539
6 43 37 1512 1591 59 2819 99 67 633
6 43 67 2772 2881 37 10189 51 2000 806
6 43 67 2772 2881 37 10189 52 228 1315
6 43 67 2772 2881 37 10189 61 2657 718
6 31 61 1800 1891 47 3983 87 67 470
14 31 61 1800 1891 47 3983 86 137 300
14 31 61 1800 1891 47 3983 88 1711 285
In a line of python:
In [2]: sorted([[max([l[n-1]-l[n] for n in range(len(l))])]+l for l in [[int(i) for i in line.split()] for line in open("file.tsv", 'r').readlines()], key=lambda line: line[0])
Where "file.tsv" is whatever file holds the data.

R compare all list elements for duplicates

I am looking at all possible paths through a graph. I have written a DFS algorithm that finds all these paths. I want to make sure that my algorithm works correctly and that no two paths are identical. My algorithm returns a list that looks as follows:
....
[[2770]]
[1] 1 2 3 52 53 54 55 56 57 58 59 60 12 11 10 9 8 78 79 80 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
[38] 130 131 132 133 134 137 138 139 140 141 142 143 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
[[2771]]
[1] 1 2 3 52 53 54 55 56 57 58 59 60 12 11 10 9 8 78 79 80 113 114 115 143 144 145 146 147 148 149 150 151 152 153 154 155 156
[38] 157 158 159 160 161 162 163 164 165 166
[[2772]]
[1] 1 2 3 52 53 54 55 56 57 58 59 60 12 11 10 9 8 78 79 80 113 114 115 143 150 151 152 153 154 155 156 157 158 159 160 161 162
[38] 163 164 165 166
As you can see, the list is 2772 elements long. This means there are 2,772 paths through this graph. How can I easily compare all the list elements to make sure there are no duplicates. Just to be clear, the same set of numbers but in a different ordering represents a different path and is not a duplicate!
Thank you for your help!
maybe something like
test<-list(1:2,3:4,5:7,1:10,3:4,4:3)
dups<-duplicated(test)
idups<-seq_along(test)[dups]

Resources