diff options
| -rw-r--r-- | challenge-317/steven-wilson/perl/ch-1.pl | 16 | ||||
| -rw-r--r-- | challenge-317/steven-wilson/python/ch-1.py | 22 | ||||
| -rw-r--r-- | challenge-317/steven-wilson/python/ch-2.py | 26 |
3 files changed, 64 insertions, 0 deletions
diff --git a/challenge-317/steven-wilson/perl/ch-1.pl b/challenge-317/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..29976f26b9 --- /dev/null +++ b/challenge-317/steven-wilson/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl + +use v5.35; +use Test2::Bundle::More; + +sub acronyms{ + my ($words, $word) = @_; + my $first = join "", map { substr($_, 0, 1) } @$words; + return $first eq $word; +} + +ok(acronyms(["Perl", "Weekly", "Challenge"], "PWC")); +ok(acronyms(["Bob", "Charlie", "Joe"], "BCJ")); +ok(!acronyms(["Morning", "Good"], "MM")); + +done_testing(); diff --git a/challenge-317/steven-wilson/python/ch-1.py b/challenge-317/steven-wilson/python/ch-1.py new file mode 100644 index 0000000000..b0d7b864ac --- /dev/null +++ b/challenge-317/steven-wilson/python/ch-1.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + + +def acronyms(words, word): + """ Given an array of words and a word, return true if concatenating the + first letter of each word in the given array matches the given word, return + false otherwise. + + >>> acronyms(["Perl", "Weekly", "Challenge"], "PWC") + True + >>> acronyms(["Bob", "Charlie", "Joe"], "BCJ") + True + >>> acronyms(["Morning", "Good"], "MM") + False + """ + return word == "".join(w[0] for w in words) + + +if __name__ == "__main__": + import doctest + + doctest.testmod(verbose=True) diff --git a/challenge-317/steven-wilson/python/ch-2.py b/challenge-317/steven-wilson/python/ch-2.py new file mode 100644 index 0000000000..7fea218224 --- /dev/null +++ b/challenge-317/steven-wilson/python/ch-2.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +from itertools import combinations + + +def friendly_strings(a, b): + """ Given two strings, return true if swapping any two letters in one + string match the other string, return false otherwise. + + >>> friendly_strings("desc", "dsec") + True + >>> friendly_strings("fuck", "fcuk") + True + >>> friendly_strings("poo", "eop") + False + >>> friendly_strings("stripe", "sprite") + True + """ + swaps = combinations(range(len(a)), 2) + return any(a[:x] + a[y] + a[x+1:y] + a[x] + a[y+1:] == b for x, y in swaps) + + +if __name__ == "__main__": + import doctest + + doctest.testmod(verbose=True) |
