-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathch-1.pl
32 lines (25 loc) · 1.16 KB
/
ch-1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/local/bin/perl
use strict;
use warnings;
use feature qw(say);
use Test::More;
use List::MoreUtils qw(firstidx frequency);
my @TESTS = (
[ 'Perl Weekly Challenge', 0 ],
[ 'Long Live Perl', 1 ],
[ 'P.O.O.P', -1 ],
[ 'tractors', 2 ],
[ 'aabbccddeeffg', 12 ],
[ 'taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu',-1 ],
[ 'LLANFAIRPWLLGWYNGYLLGOGERYCHWYRNDROBWLLLLANTYSILIOGOGOGOCH', 4 ],
[ 'Krung Thep Mahanakhon Amon Rattanakosin Mahinthara Ayuthaya Mahadilok Phop Noppharat Ratchathani Burirom Udomratchaniwet Mahasathan Amon Piman Awatan Sathit Sakkathattiya Witsanukam Prasit', 0 ],
[ 'krung thep mahanakhon amon rattanakosin mahinthara ayuthaya mahadilok phop noppharat ratchathani burirom udomratchaniwet mahasathan amon piman awatan sathit sakkathattiya witsanukam prasit', 4 ],
);
is( first_unique($_->[0]), $_->[1] ) foreach @TESTS;
is( u($_->[0]), $_->[1] ) foreach @TESTS;
done_testing();
sub first_unique {
my %counts = frequency my @p = split //, pop;
firstidx { $counts{$_} < 2 } @p;
}
sub u{my%c;$c{$_}++for@_=split//,pop;firstidx{$c{$_}<2}@_}