So this morning I was thinking about different ways to work out of a list has no duplicate values in #RakuLang so far :
Use the chaining metaoperator. Make sure we compare the last item to the first.
If all of the items in the list only match one item in the list it's not duplicated.
@l.Bag (==) @l.Set
If the set of items in the list is equal to the Bag of items in the list it's not got duplicates.
@l.unique ~~ @l
Use the unique method...
sub MAIN(*@i){ @i.combinations(3).grep( { [!==] (|@^a,@^a[0]) } ).elems.say }
#PerlWeeklyChallenge Week 234 part 2.
#rakulang #perlweeklychallenge
#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
#RakuLang, a language for Gremlins! But I think the documentation has improved, especially with the new docs site launch earlier this year! Also, there are a few books available. https://buttondown.email/hillelwayne/archive/raku-a-language-for-gremlins/
@jns First I thought #Ruby could do that, too. But the () operator can't be overridden. But [] can, so in Ruby it gets pretty close :-)
ruby -e 'class String;def [](arg); puts self if arg == "print"; end; end; "Hello, World"["print"]'
Hello, World
Re-opening classes like this is pretty common in Ruby, that's why you don't have to include a Module for it.
But I love how you can define pretty much any operator in #RakuLang and that you aren't limited to a set of operators.
You know you're in need of a holiday when you see a humorous meme and immediately think of #RakuLang
He'd have got away with it if it weren't for the pesky implementation details:
```
raku -MMONKEY-TYPING -e 'augment class Str { method CALL-ME(Str $m) { self."$m"() }}; "Hello, World"("print")'
Hello, World
```
A quick heads up for anyone who may be using the #RakuLang module Kivuli on AWS ElasticBeanstalk: it appears that with Amazon Linux 2/3.60 they've "fixed" the problem whereby you can't get the temporary API token from within the docker container so you *must* have the token. So you shouldn't use the `:no-api-token` for Kivuli.
I'll look at making that a bit more intelligent, but in the meantime you might find you have to change your code in EB.
As programmers we may have have our pet favourite languages for:
1. Productivity.
2. Expressive power, features.
3. Performance.
4. Debuggability (something you can use at work).
#Rakulang/#Clojure for 1 and 2 right now, someday Raku/#commonlisp .
Go for 3 and 4 at the moment, someday Rust/C++ for 3.
I honestly don't care about 4. I'm open to using whatever.
Let me know about yours in the replies!
%error-to-file.push(%error.invert);
seems to do exactly what I want! #RakuLang
i’ve been playing with #raku on the weekends, and it has already replaced #rust as my current favorite programming language.
i like the terseness, the large number of available methods/operators for working with various kinds of collections, the built-in command line parsing, the way rational numbers are handled … i could go on.
i’m already writing a ton of scripts in Raku for personal use. hoping to maybe build something larger one day.
#raku #rust #rakulang #programming
@for4four @fosskers @barubary
#rakulang has the feed operator
https://docs.raku.org/language/operators#infix_==%3E
While I don’t use #rakulang very often I am impressed by its capabilities. This blog shows how the built in grammar abilities allow for an elegant solution to a problem with Roman Numerals.
@samebchase
My quick stab at a #RakuLang solution. Full source code is in the ALT text of the image. Note that this uses the #RakuLang definition of "word", and thus gives slightly different results on their sample. Also, “words do not appear in the result more than once” was vague to me -- I’ve implemented it as words that appear more than once are not included in the output. But making it the other interpretation would actually simply the code a bit…