On Tue, 31 Dec 2019, Marc Chantreux wrote:
> hello,
>
> 2020 describes itself as it is composed by
>
> 2 0
> 0 1
> 2 2
> 0 3
>
> perfect golf excuse! I have :
>
> sub is_autobiographic (\x) {
> my \s = x.Str;
> my @r = s.comb;
> my %appearance_of;
> %appearance_of{$_}++ for @r;
> x ~~ join '', (%appearance_of{$_}//0 for 0..^@r);
> }
>
> (^∞
> ).race( :10000batch,:10degree
> ).grep( &is_autobiographic
> ).head(10).map(*.say)
>
> anyone with something simpler?
>
Here is my entry, having a Bag count the occurences of letters,
instead of the loop over @r you used. It also doesn't assemble
a string out of the bag to compare the input to, but consults
the bag directly for each digit:
sub is-autobiographic (\x) {
my \bag = x.comb.Bag;
[and] x.comb.kv.map: {
bag{~$^i} == $^v
}
}
Regards,
Tobias
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk