Scimon Proctor · @scimon
152 followers · 541 posts · Server glasgow.social

So this morning I was thinking about different ways to work out of a list has no duplicate values in so far :

[!==] (|@l,@l[0])

Use the chaining metaoperator. Make sure we compare the last item to the first.

so all(@l) == one(@l)

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...

#rakulang

Last updated 1 year ago

Scimon Proctor · @scimon
152 followers · 540 posts · Server glasgow.social

sub MAIN(*@i){ @i.combinations(3).grep( { [!==] (|@^a,@^a[0]) } ).elems.say }

Week 234 part 2.

#rakulang #perlweeklychallenge

Last updated 1 year ago

seaker · @seaker
1 followers · 4 posts · Server fosstodon.org


233, Task 2

my solution:
```
my @n = +«$*IN.words;
my %freq = @N.Bag;
put @N.sort({ %freq{$_}, -$_ }).join(',');
```

#rakulang #perlweeklychallenge

Last updated 1 year ago

seaker · @seaker
1 followers · 4 posts · Server fosstodon.org


233, Task 1

my solution:
```
put $*IN.words.combinations(2).grep({ .[0].comb.Set eqv .[1].comb.Set }).join("\n");
```

#rakulang #perlweeklychallenge

Last updated 1 year ago

Massa 👽 Humberto · @massa
226 followers · 1175 posts · Server hachyderm.io

233/02:

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

Last updated 1 year ago

Massa 👽 Humberto · @massa
226 followers · 1173 posts · Server hachyderm.io

231/02:

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

Last updated 1 year ago

Massa 👽 Humberto · @massa
226 followers · 1173 posts · Server hachyderm.io

231/01:

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

Last updated 1 year ago

Massa 👽 Humberto · @massa
226 followers · 1172 posts · Server hachyderm.io

231/01:

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

Last updated 1 year ago

Paul Buetow · @snonux
82 followers · 562 posts · Server fosstodon.org

, 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. buttondown.email/hillelwayne/a

#rakulang

Last updated 1 year ago

Paul Buetow · @snonux
82 followers · 562 posts · Server fosstodon.org

@jns First I thought 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 and that you aren't limited to a set of operators.

#ruby #rakulang

Last updated 1 year ago

Jonathan Stowe · @jns
56 followers · 309 posts · Server fosstodon.org

You know you're in need of a holiday when you see a humorous meme and immediately think of

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
```

#rakulang

Last updated 1 year ago

Jonathan Stowe · @jns
56 followers · 306 posts · Server fosstodon.org

A quick heads up for anyone who may be using the 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.

#rakulang

Last updated 1 year ago

Samuel Chase · @samebchase
312 followers · 366 posts · Server fantastic.earth

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).

/#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!

#rakulang

Last updated 1 year ago

Solomon Foster · @colomon
99 followers · 622 posts · Server wandering.shop

@gfldex @lizmat Oh, hey,

%error-to-file.push(%error.invert);

seems to do exactly what I want!

#rakulang

Last updated 1 year ago

Solomon Foster · @colomon
99 followers · 622 posts · Server wandering.shop

@kithrup That's the Perl 5 solution. But I think I just found the solution -- Hash::invert actually does exactly what I want. Dunno how I missed that the first four times I looked…

#rakulang

Last updated 1 year ago

Samuel Chase · @samebchase
312 followers · 365 posts · Server fantastic.earth

@s3thi yayayayayayay it made my day to hear that you like !

The community is fun and friendly as well.

#rakulang

Last updated 1 year ago

ankur sethi is alive and well · @s3thi
156 followers · 457 posts · Server fantastic.earth

i’ve been playing with on the weekends, and it has already replaced 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

Last updated 1 year ago

Felix · @leobm
299 followers · 4424 posts · Server norden.social
adamcrussell · @adamcrussell
66 followers · 143 posts · Server mastodon.sdf.org

While I don’t use 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.

andrewshitov.com/2023/07/24/ca

#rakulang

Last updated 1 year ago

Solomon Foster · @colomon
98 followers · 598 posts · Server wandering.shop

@samebchase
My quick stab at a solution. Full source code is in the ALT text of the image. Note that this uses the 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…

#rakulang

Last updated 1 year ago