Anton Antonov |
How can I optimize (get faster execution times) for the following code: |
19:46 |
|
|
``` |
|
|
|
my @chars =['a' ... 'z'].roll(4); |
|
|
|
my %init = @chars[*- 1] => %(ROOT0 => 1e0); |
|
|
|
my %res = reduce(-> %a, $x { { $x => %a.push((ROOT2 => 1e0)) } }, (%init, |@chars[^(*- 1)].reverse)); |
|
|
|
``` |
|
|
|
it produces `%res` like this: |
|
|
|
``` |
|
|
|
{g => {ROOT2 => 1, q => {ROOT2 => 1, l => {ROOT2 => 1, c => {ROOT0 => 1}}}}} |
|
|
|
``` |
|
|
gfldex |
'@' ~ discord-user(694526400488669234.Str) With a nested structure you might be better of with custom classes then with Hash. As I understand it, reduce will copy ever growing Hashes into even bigger Hashes. |
21:55 |
|
Anton Antonov |
'@' ~ discord-user(195453211409121280.Str) Thanks! I tried that first -- having a tree of objects. I thought moving to hashes would speed-up things. (Here is a more detailed description, in case you are curious: github.com/antononcube/Raku-ML-Tri...tion-notes ) |
21:58 |
|
|
'@' ~ discord-user(195453211409121280.Str) Thanks! I tried that first -- having a tree of objects. I thought moving to hashes would speed-up things. (Here is a more detailed description, in case you are curious: github.com/antononcube/Raku-ML-Tri...tion-notes ) |
22:02 |
|
|
'@' ~ discord-user(195453211409121280.Str) Your comment makes re-examine my object-based implementation... |
|
|
lakmatiol |
how would I go about checking if a string contains an uppercase letter, `[A-Z]` is not a valid raku regex, `[A..Z]` doesn't seem to do what I need it to |
22:43 |
|
Morfent |
m:``` |
22:45 |
|
|
use v6; |
|
|
|
say m:g/ <upper> / given 'abCdeFgh'; |
|
|
|
``` |
|
|
|
m:``` |
|
|
|
use v6; |
|
|
|
say so m:g/ <upper> / given 'abCdeFgh'; |
|
|
|
``` |
|
|
|
m:``` |
22:47 |
|
|
use v6; |
|
|
|
say so m:1st/ <upper> / given 'abCdeFgh'; |
|
|
|
``` |
|
|
|
m:``` |
22:48 |
|
|
use v6; |
|
|
|
say so m:1st/ <.upper> / given 'abCdeFgh'; |
|
|
|
``` |
|
|
|
'@' ~ discord-user(207089259730042881.Str) this is one way |
|
|
|
m: ``` |
22:52 |
|
|
say so m:1st/ <[ A..Z ]> / given 'abCdeFgh'; |
|
|
|
``` |
|
|
|
m: ``` |
22:53 |
|
|
use v6; |
|
|
|
say so m:1st/ <[ A..Z ]> / given 'abCdeFgh'; |
|
|
|
``` |
|
|
|
m:``` |
|
|
|
use v6; |
|
|
|
say so m:1st/ <[ A..Z ]> / given 'abCdeFgh'; |
|
|
|
``` |
|
|
|
this will match ascii A-Z specifically |
|
|