I'm trying to generate a Seq
of random options where consecutive repeats are not allowed:
> (<F R U>.roll(*).grep(* ne *))[^10]
((R F) (F U) (R F) (F R) (U R) (R F) (R F) (U F) (R U) (U R))
Why does using grep
in this way result in nested pairs? And how can I achieve what I'm looking for? Using .flat
above will still allow consecutive repeats.
( R U F U F U R F R U ... )
Save 50% of your time, and reduce thousands of mouse clicks for you every day! You can apply the Advanced Filter feature to filter out duplicates in a list and only keep the unique values. Please do as follows. 1. Select the list you need to filter out duplicates, then click Data > Advanced. See screenshot: 2.
Q: Given a sequence of random numbers, find the start and end positions of runs of five or more consecutive numbers that are greater than zero. A: Use the rle () function. For example, let’s apply rle () to the following sequence of numbers. seq3 = c(2,2,2,2,2,5,3,7,7,7,2,2,5,5,5,3,3,3) ( rle.seq3 = rle(seq3) )
There are no limitations there. We do have dedicated training section on the FILTER function, including multiple criteria, in our Elevate Excel Training Program. One issue that will eventually arise with this solution is when columns are added or deleted from the source data table.
Excel Filter out Duplicates 1 Select the list you need to filter out duplicates, then click Data > Advanced . 2 In the Advanced Filter dialog box, select Filter the list, in-place option in the Action section, check the Unique records only box, and then click the OK button. See More....
how can I achieve what I'm looking for?
I believe the squish
method will do what you want:
say <F R U>.roll(*).squish.head(20)
This produces:
(U R F U F R F R F U F R U R F U R U R F)
Why does using grep in this way result in nested pairs?
Because grep
(and map
too) on something with an arity greater than 1 will work by breaking the list into chunks of that size. Thus given A B C D
, the first call to the grep
block gets A B
, the second C D
, and so on. What's really needed in this case, however, is a lagged value. One could use a state
variable in the block passed to grep
to achieve this, however for this problem squish
is a much simpler solution.
You could employ a simple regex using the <same>
zero-width matcher. Below in the Raku REPL:
> my $a = (<F R U>.roll(*))[^20].comb(/\w/).join; say $a;
RRFUURFFFFRRFRFUFUUU
> say $/ if $a ~~ m:g/ \w <!same> /;
(「R」 「F」 「U」 「R」 「F」 「R」 「F」 「R」 「F」 「U」 「F」 「U」)
https://docs.raku.org/language/regexes#Predefined_Regexes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With