@@ -46,14 +46,14 @@ comboGeneral(4, 3)
4646permuteGeneral(4 , 3 )
4747 [,1 ] [,2 ] [,3 ]
4848 [1 ,] 1 2 3
49- [2 ,] 2 1 3
50- [3 ,] 3 1 2
51- [4 ,] 1 3 2
49+ [2 ,] 1 2 4
50+ [3 ,] 1 3 2
51+ [4 ,] 1 3 4
5252 . . . .
5353 . . . .
54- [21 ,] 4 2 3
55- [22 ,] 2 4 3
56- [23 ,] 3 4 2
54+ [21 ,] 4 2 1
55+ [22 ,] 4 2 3
56+ [23 ,] 4 3 1
5757[24 ,] 4 3 2
5858
5959# # For combinations/permutations with repetition, simply
@@ -69,7 +69,7 @@ comboGeneral(4, 3, repetition = TRUE)
6969# # They are very efficient
7070system.time(comboGeneral(25 ,13 ))
7171 user system elapsed
72- 0.136 0.062 0.198
72+ 0.124 0.058 0.182
7373
7474nrow(comboGeneral(25 ,13 ))
7575[1 ] 5200300
@@ -111,20 +111,20 @@ p <- permuteGeneral(v = s,
111111head(p )
112112 [,1 ] [,2 ] [,3 ] [,4 ] [,5 ] [,6 ]
113113[1 ,] 19 22 327 354 454 1176
114- [2 ,] 22 19 327 354 454 1176
115- [3 ,] 327 19 22 354 454 1176
116- [4 ,] 19 327 22 354 454 1176
117- [5 ,] 22 327 19 354 454 1176
118- [6 ,] 327 22 19 354 454 1176
114+ [2 ,] 19 22 327 454 354 1176
115+ [3 ,] 19 22 354 327 454 1176
116+ [4 ,] 19 22 354 454 327 1176
117+ [5 ,] 19 22 454 327 354 1176
118+ [6 ,] 19 22 454 354 327 1176
119119
120120tail(p )
121121 [,1 ] [,2 ] [,3 ] [,4 ] [,5 ] [,6 ]
122- [3955 ,] 199 187 354 287 149 1176
123- [3956 ,] 187 199 354 287 149 1176
124- [3957 ,] 354 199 187 287 149 1176
125- [3958 ,] 199 354 187 287 149 1176
126- [3959 ,] 187 354 199 287 149 1176
127- [3960 ,] 354 187 199 287 149 1176
122+ [3955 ,] 354 287 149 187 199 1176
123+ [3956 ,] 354 287 149 199 187 1176
124+ [3957 ,] 354 287 187 149 199 1176
125+ [3958 ,] 354 287 187 199 149 1176
126+ [3959 ,] 354 287 199 149 187 1176
127+ [3960 ,] 354 287 199 187 149 1176
128128
129129
130130# # Get combinations such that the product is between
@@ -147,9 +147,9 @@ comboGeneral(5, 7, TRUE, constraintFun = "prod",
147147# # without any constraints. Simply pick the function you wish
148148# # to be applied, and set keepResults to TRUE.
149149set.seed(99 )
150- mySamp <- rnorm(5 , 100 , 5 )
150+ mySamp <- sort( rnorm(5 , 100 , 5 ) )
151151mySamp
152- [1 ] 101.06981 102.39829 100.43914 102.21929 98.18581
152+ [1 ] 98.18581 100.43914 101.06981 102.21929 102.39829
153153comboGeneral(mySamp , m = 4 ,
154154 repetition = TRUE ,
155155 constraintFun = " sum" ,
@@ -182,7 +182,7 @@ getPermsWithSpecificRepetition <- function(z, n) {
182182 b [! myDupes , ]
183183}
184184
185- system.time(getPermsWithSpecificRepetition(a , 6 ))
185+ system.time(test <- getPermsWithSpecificRepetition(a , 6 ))
186186 user system elapsed
187187 4.300 0.028 4.331
188188```
@@ -197,8 +197,7 @@ system.time(test2 <- permuteGeneral(unique(a), 6, freqs = rle(a)$lengths))
197197 user system elapsed
198198 0 0 0
199199
200- identical(test [do.call(order ,as.data.frame(test )),],
201- test2 [do.call(order ,as.data.frame(test2 )),])
200+ identical(test , test2 )
202201[1 ] TRUE
203202```
204203
@@ -226,11 +225,11 @@ permuteGeneral(3, freqs = c(1,2,2))
226225permuteGeneral(3 , 2 , freqs = c(1 ,2 ,2 ))
227226 [,1 ] [,2 ]
228227[1 ,] 1 2
229- [2 ,] 2 1
230- [3 ,] 1 3
231- [4 ,] 3 1
232- [5 ,] 2 2
233- [6 ,] 2 3
228+ [2 ,] 1 3
229+ [3 ,] 2 1
230+ [4 ,] 2 2
231+ [5 ,] 2 3
232+ [6 ,] 3 1
234233[7 ,] 3 2
235234[8 ,] 3 3
236235
@@ -412,8 +411,8 @@ primeFactorize(123456789)
412411
413412# # or for an entire vector
414413set.seed(100 )
415- > myVec <- sample(- 100000000 : 100000000 , 5 )
416- > divisorsRcpp(myVec , namedList = TRUE )
414+ myVec <- sample(- 100000000 : 100000000 , 5 )
415+ divisorsRcpp(myVec , namedList = TRUE )
417416$ `-38446778`
418417[1 ] - 38446778 - 19223389 - 2 - 1 1
419418[6 ] 2 19223389 38446778
@@ -480,13 +479,13 @@ object.size(myPs)
480479# # primes under a billion!!!
481480system.time(primeSieve(10 ^ 9 ))
482481 user system elapsed
483- 1.378 0.109 1.489
482+ 1.289 0.091 1.382
484483
485484
486485# # Enumerate the number of primes below trillion
487486system.time(underOneTrillion <- primeCount(10 ^ 12 ))
488487 user system elapsed
489- 0.490 0.001 0.491
488+ 0.484 0.000 0.485
490489
491490underOneTrillion
492491[1 ] 37607912018
0 commit comments