sub MAIN(*@i){ @i.combinations(3).grep( { [!==] (|@^a,@^a[0]) } ).elems.say }
#PerlWeeklyChallenge Week 234 part 2.
#rakulang #perlweeklychallenge
sub MAIN(*@w) { say ( [(&)] @w.map(*.comb.Bag) ).map({|($_.key xx $_.value)}).sort; }
#PerlWeeklyChallenge 234 part 1.
#rakulang
#perlweeklychallenge 233, Task 2
my solution:
```
my @n = +Β«$*IN.words;
my %freq = @N.Bag;
put @N.sort({ %freq{$_}, -$_ }).join(',');
```
#rakulang #perlweeklychallenge
#rakulang
#perlweeklychallenge 233, Task 1
my solution:
```
put $*IN.words.combinations(2).grep({ .[0].comb.Set eqv .[1].comb.Set }).join("\n");
```
#rakulang #perlweeklychallenge
#perlweeklychallenge 233/02:
#rakulang
You are given an array of integers.
Write a script to sort the given array in increasing order based on the frequency of the values. If multiple values have the same frequency then sort them in decreasing order.
my answer:
```
sub frequency-sort(@_) {
my $frequencies = @_.Bag;
@_.sort: { $frequencies{$^a} <=> $frequencies{$^b} || $^b <=> $^a }
}
```
#perlweeklychallenge #rakulang
#perlweeklychallenge 231/02:
#rakulang
You are given a list of passenger details in the form β9999999999A1122β, where 9 denotes the phone number, A the sex, 1 the age and 2 the seat number.
Write a script to return the count of all senior citizens (age >= 60).
my answer:
```
sub number-of-senior-citizens(@_) {
@_.grep(/^ \d ** 10 \D (\d\d) <?{$0 β₯ 60}> \d ** 2 $/).elems
}
```
#perlweeklychallenge #rakulang
#perlweeklychallenge 231/01:
#rakulang
You are given a list of passenger details in the form β9999999999A1122β, where 9 denotes the phone number, A the sex, 1 the age and 2 the seat number.
Write a script to return the count of all senior citizens (age >= 60).
my answer:
```
sub number-of-senior-citizens(@_) {
@_.grep(/^ \d ** 10 \D (\d\d) <?{$0 β₯ 60}> \d ** 2 $/).elems
}
```
#perlweeklychallenge #rakulang
#perlweeklychallenge 231/01:
#rakulang
You are given an array of distinct integers.
Write a script to find all elements that is neither minimum nor maximum. Return -1 if you canβt.
my answer:
```
sub without-min-and-max(@_) {
@_.grep: * β @_.minmax.bounds or -1
}
```
#perlweeklychallenge #rakulang
It's nice when I'm the first pull request on the #PerlWeeklyChallenge.
Part one this week is very simple in #Raku thanks to the is-prime method.
Part two is a nice little bit of recursion. Woke me right up... well mostly, time for more coffee.
Enjoyed spending some time coding this weekend. #perl #python #golang for the #perlweeklychallenge
#perl #python #golang #perlweeklychallenge