diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-11-13 00:37:43 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-13 00:37:43 +0000 |
| commit | 68ac0de506ae75699f29e523b3ae68bb264d2d9e (patch) | |
| tree | bb33fa5ad15fba321fb586629a922561400619ff | |
| parent | de8c5d7e100bd5ff879c8563a5f16eb2c153c261 (diff) | |
| parent | 62e0b35d2400262542d9a4083c735419d37bedf6 (diff) | |
| download | perlweeklychallenge-club-68ac0de506ae75699f29e523b3ae68bb264d2d9e.tar.gz perlweeklychallenge-club-68ac0de506ae75699f29e523b3ae68bb264d2d9e.tar.bz2 perlweeklychallenge-club-68ac0de506ae75699f29e523b3ae68bb264d2d9e.zip | |
Merge pull request #5202 from pauloscustodio/devel
Devel
30 files changed, 434 insertions, 80 deletions
diff --git a/challenge-005/paulo-custodio/Makefile b/challenge-005/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-005/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-005/paulo-custodio/perl/ch-1.pl b/challenge-005/paulo-custodio/perl/ch-1.pl index cd33db9b46..6db4ce2911 100644 --- a/challenge-005/paulo-custodio/perl/ch-1.pl +++ b/challenge-005/paulo-custodio/perl/ch-1.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 005 # diff --git a/challenge-005/paulo-custodio/perl/ch-2.pl b/challenge-005/paulo-custodio/perl/ch-2.pl index 59ab0fb365..69dd53f3dd 100644 --- a/challenge-005/paulo-custodio/perl/ch-2.pl +++ b/challenge-005/paulo-custodio/perl/ch-2.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 005 # diff --git a/challenge-005/paulo-custodio/python/ch-1.py b/challenge-005/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..dfb7dac235 --- /dev/null +++ b/challenge-005/paulo-custodio/python/ch-1.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +# Challenge 005 +# +# Challenge #1 +# Write a program which prints out all anagrams for a given word. For more +# information about Anagram, please check this wikipedia page. +# create a hash of all words in dictionary where key is sorted list of letters +# therefore two anagrams have the same key + +import sys +import re + +def read_file(filename): + with open(filename) as f: + return f.readlines() + +def read_words(lines): + words = [] + for line in lines: + word = line.strip() + if not re.search(r"\W", word): + words.append(word) + return words + +def get_word_key(word): + letters = sorted([x for x in word.lower()]) + return "".join(letters) + +def print_anagrams(myword): + myword_key = get_word_key(myword) + for word in read_words(read_file("words.txt")): + if get_word_key(word)==myword_key: + print(word.lower()) + +print_anagrams(sys.argv[1]) diff --git a/challenge-005/paulo-custodio/python/ch-2.py b/challenge-005/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..366717d95f --- /dev/null +++ b/challenge-005/paulo-custodio/python/ch-2.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +# Challenge 005 +# +# Challenge #2 +# Write a program to find the sequence of characters that has the most anagrams. +# +# create a hash of all words in dictionary where key is sorted list of letters +# therefore two anagrams have the same key + +import sys +import re + +def read_file(filename): + with open(filename) as f: + return f.readlines() + +def read_words(lines): + words = [] + for line in lines: + word = line.strip() + if not re.search(r"\W", word): + words.append(word) + return words + +def get_word_key(word): + letters = sorted([x for x in word.lower()]) + return "".join(letters) + +def print_largest_anagram(): + anagrams = {} + max_anagrams = 0 + for word in read_words(read_file("words.txt")): + if len(word) >= 2: + key = get_word_key(word) + if key in anagrams: + anagrams[key] += 1 + else: + anagrams[key] = 1 + max_anagrams = max(max_anagrams, anagrams[key]) + print(f"Maximum of {max_anagrams} anagrams") + for key in sorted(anagrams): + if anagrams[key]==max_anagrams: + print(key) + +print_largest_anagram() diff --git a/challenge-005/paulo-custodio/t/test-1.yaml b/challenge-005/paulo-custodio/t/test-1.yaml index 63708186b7..920baa4d67 100644 --- a/challenge-005/paulo-custodio/t/test-1.yaml +++ b/challenge-005/paulo-custodio/t/test-1.yaml @@ -27,4 +27,3 @@ |recaps |scrape |spacer - |casper diff --git a/challenge-005/paulo-custodio/t/test-2.yaml b/challenge-005/paulo-custodio/t/test-2.yaml index f63585ea79..0fc57c3cc5 100644 --- a/challenge-005/paulo-custodio/t/test-2.yaml +++ b/challenge-005/paulo-custodio/t/test-2.yaml @@ -4,8 +4,6 @@ input: output: | |Maximum of 8 anagrams - |aceprs - |aels |aelst |aerst |egor diff --git a/challenge-005/paulo-custodio/test.pl b/challenge-005/paulo-custodio/test.pl deleted file mode 100644 index ba6c37260b..0000000000 --- a/challenge-005/paulo-custodio/test.pl +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env perl -use Modern::Perl; -use Test::More; -require '../../challenge-001/paulo-custodio/test.pl'; diff --git a/challenge-006/paulo-custodio/Makefile b/challenge-006/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-006/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-006/paulo-custodio/perl/ch-1.pl b/challenge-006/paulo-custodio/perl/ch-1.pl index 726898318c..30763f99b7 100644 --- a/challenge-006/paulo-custodio/perl/ch-1.pl +++ b/challenge-006/paulo-custodio/perl/ch-1.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 006 # diff --git a/challenge-006/paulo-custodio/perl/ch-2.pl b/challenge-006/paulo-custodio/perl/ch-2.pl index 748a86aaa5..d425880ee2 100644 --- a/challenge-006/paulo-custodio/perl/ch-2.pl +++ b/challenge-006/paulo-custodio/perl/ch-2.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 006 # diff --git a/challenge-006/paulo-custodio/python/ch-1.py b/challenge-006/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..5834c84c81 --- /dev/null +++ b/challenge-006/paulo-custodio/python/ch-1.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +# Challenge 006 +# +# Challenge #1 +# Create a script which takes a list of numbers from command line and print the +# same in the compact form. For example, if you pass "1,2,3,4,9,10,14,15,16" +# then it should print the compact form like "1-4,9,10,14-16". + +import sys + +nums = sorted([int(x) for x in sys.argv[1].split(",")]) +output = "" +while nums: + n = nums.pop(0) + output += str(n) + if len(nums)>1 and nums[0]==n+1 and nums[1]==n+2: + while len(nums)>0 and nums[0]==n+1: + n = nums.pop(0) + output += "-"+str(n) + if nums: + output += "," +print(output) diff --git a/challenge-006/paulo-custodio/python/ch-2.py b/challenge-006/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..11b69ae90b --- /dev/null +++ b/challenge-006/paulo-custodio/python/ch-2.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +# Challenge 006 +# +# Challenge #2 +# Create a script to calculate Ramanujan's constant with at least 32 digits of +# precision. Find out more about it here. +# +# The standard IEEE 754 double-precision binary floating-point format: binary64 +# gives only 15 to 17 significant decimal digits +# Therefore must use the bignum library + +from decimal import * + +getcontext().prec = 128 + +def pi(): + getcontext().prec += 2 # extra digits for intermediate steps + three = Decimal(3) # substitute "three=3.0" for regular floats + lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24 + while s != lasts: + lasts = s + n, na = n+na, na+8 + d, da = d+da, da+32 + t = (t * n) / d + s += t + getcontext().prec -= 2 + return +s # unary plus applies the new precision + +def exp(x): + getcontext().prec += 2 + i, lasts, s, fact, num = 0, 0, 1, 1, 1 + while s != lasts: + lasts = s + i += 1 + fact *= i + num *= x + s += num / fact + getcontext().prec -= 2 + return +s + +e = pi() * Decimal(163).sqrt() +k = exp(e) + +print(str(k)[:31]) diff --git a/challenge-006/paulo-custodio/test.pl b/challenge-006/paulo-custodio/test.pl deleted file mode 100644 index ba6c37260b..0000000000 --- a/challenge-006/paulo-custodio/test.pl +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env perl -use Modern::Perl; -use Test::More; -require '../../challenge-001/paulo-custodio/test.pl'; diff --git a/challenge-081/paulo-custodio/Makefile b/challenge-081/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-081/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-081/paulo-custodio/perl/ch-1.pl b/challenge-081/paulo-custodio/perl/ch-1.pl index 761c27d74d..317e2f90ee 100644 --- a/challenge-081/paulo-custodio/perl/ch-1.pl +++ b/challenge-081/paulo-custodio/perl/ch-1.pl @@ -1,8 +1,8 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 081 # -# TASK #1 › Common Base String +# TASK #1 > Common Base String # Submitted by: Mohammad S Anwar # You are given 2 strings, $A and $B. # diff --git a/challenge-081/paulo-custodio/perl/ch-2.pl b/challenge-081/paulo-custodio/perl/ch-2.pl index 11d77685f7..d1184a5dff 100644 --- a/challenge-081/paulo-custodio/perl/ch-2.pl +++ b/challenge-081/paulo-custodio/perl/ch-2.pl @@ -1,8 +1,8 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 081 # -# TASK #2 › Frequency Sort +# TASK #2 > Frequency Sort # Submitted by: Mohammad S Anwar # You are given file named input. # diff --git a/challenge-081/paulo-custodio/python/ch-1.py b/challenge-081/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..be33af8625 --- /dev/null +++ b/challenge-081/paulo-custodio/python/ch-1.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +# Challenge 081 +# +# TASK #1 > Common Base String +# Submitted by: Mohammad S Anwar +# You are given 2 strings, $A and $B. +# +# Write a script to find out common base strings in $A and $B. +# +# A substring of a string $S is called base string if repeated concatenation +# of the substring results in the string. +# +# Example 1: +# Input: +# $A = "abcdabcd" +# $B = "abcdabcdabcdabcd" +# +# Output: +# ("abcd", "abcdabcd") +# Example 2: +# Input: +# $A = "aaa" +# $B = "aa" +# +# Output: +# ("a") + +import sys + +def base_strings(s): + bases = [] + for i in range(1, len(s)+1): + if len(s)%i==0: + base = s[:i] + if base*int(len(s)/i) == s: + bases.append(base) + return bases + +base_a = set(base_strings(sys.argv[1])) +base_b = set(base_strings(sys.argv[2])) +result = sorted(list(base_a.intersection(base_b))) +print("(" + ", ".join(['"'+x+'"' for x in result]) + ")") diff --git a/challenge-081/paulo-custodio/python/ch-2.py b/challenge-081/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..930f64f8bc --- /dev/null +++ b/challenge-081/paulo-custodio/python/ch-2.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +# Challenge 081 +# +# TASK #2 > Frequency Sort +# Submitted by: Mohammad S Anwar +# You are given file named input. +# +# Write a script to find the frequency of all the words. +# +# It should print the result as first column of each line should be the frequency of the the word followed by all the words of that frequency arranged in lexicographical order. Also sort the words in the ascending order of frequency. +# +# INPUT file +# West Side Story +# +# The award-winning adaptation of the classic romantic tragedy "Romeo and Juliet". The feuding families become two warring New York City gangs, the white Jets led by Riff and the Latino Sharks, led by Bernardo. Their hatred escalates to a point where neither can coexist with any form of understanding. But when Riff's best friend (and former Jet) Tony and Bernardo's younger sister Maria meet at a dance, no one can do anything to stop their love. Maria and Tony begin meeting in secret, planning to run away. Then the Sharks and Jets plan a rumble under the highway--whoever wins gains control of the streets. Maria sends Tony to stop it, hoping it can end the violence. It goes terribly wrong, and before the lovers know what's happened, tragedy strikes and doesn't stop until the climactic and heartbreaking ending. +# NOTE +# For the sake of this task, please ignore the following in the input file: +# +# . " ( ) , 's -- +# OUTPUT +# 1 But City It Jet Juliet Latino New Romeo Side Story Their Then West York adaptation any anything at award-winning away become before begin best classic climactic coexist control dance do doesn't end ending escalates families feuding form former friend gains gangs goes happened hatred heartbreaking highway hoping in know love lovers meet meeting neither no one plan planning point romantic rumble run secret sends sister streets strikes terribly their two under understanding until violence warring what when where white whoever wins with wrong younger +# +# 2 Bernardo Jets Riff Sharks The by it led tragedy +# +# 3 Maria Tony a can of stop +# +# 4 to +# +# 9 and the + +import fileinput +import re + +def read_input(): + lines = [] + for line in fileinput.input(): + lines.append(line) + return lines + +def get_word_freq(lines): + words = {} + for line in lines: + line = re.sub(r"""[."(),]|--|'s""", " ", line) + for word in line.split(): + if word in words: + words[word] += 1 + else: + words[word] = 1 + return words + +def order_by_freq(words): + freqs = [] + for word, freq in words.items(): + while len(freqs) <= freq: + freqs.append([]) + freqs[freq].append(word) + freqs[freq].sort() + return freqs + +def print_freqs(freqs): + for freq in range(1, len(freqs)): + if freqs[freq]: + print(freq, " ".join([x for x in freqs[freq]])) + print() + +print_freqs(order_by_freq(get_word_freq(read_input()))) diff --git a/challenge-081/paulo-custodio/t/test-1.yaml b/challenge-081/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..0a9859e8e7 --- /dev/null +++ b/challenge-081/paulo-custodio/t/test-1.yaml @@ -0,0 +1,10 @@ +- setup: + cleanup: + args: abcdabcd abcdabcdabcdabcd + input: + output: ("abcd", "abcdabcd") +- setup: + cleanup: + args: aaa aa + input: + output: ("a") diff --git a/challenge-081/paulo-custodio/t/test-2.yaml b/challenge-081/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..2bd0de5422 --- /dev/null +++ b/challenge-081/paulo-custodio/t/test-2.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: input + input: + output: | + |1 But City It Jet Juliet Latino New Romeo Side Story Their Then West York adaptation any anything at award-winning away become before begin best classic climactic coexist control dance do doesn't end ending escalates families feuding form former friend gains gangs goes happened hatred heartbreaking highway hoping in know love lovers meet meeting neither no one plan planning point romantic rumble run secret sends sister streets strikes terribly their two under understanding until violence warring what when where white whoever wins with wrong younger + | + |2 Bernardo Jets Riff Sharks The by it led tragedy + | + |3 Maria Tony a can of stop + | + |4 to + | + |9 and the + | diff --git a/challenge-081/paulo-custodio/test.pl b/challenge-081/paulo-custodio/test.pl deleted file mode 100644 index ff97302435..0000000000 --- a/challenge-081/paulo-custodio/test.pl +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/perl - -use Modern::Perl; -use Test::More; - -is capture("perl/ch-1.pl abcdabcd abcdabcdabcdabcd"), <<END; -("abcd", "abcdabcd") -END -is capture("perl/ch-1.pl aaa aa"), <<END; -("a") -END - - -is capture("perl/ch-2.pl input"), <<END; -1 But City It Jet Juliet Latino New Romeo Side Story Their Then West York adaptation any anything at award-winning away become before begin best classic climactic coexist control dance do doesn't end ending escalates families feuding form former friend gains gangs goes happened hatred heartbreaking highway hoping in know love lovers meet meeting neither no one plan planning point romantic rumble run secret sends sister streets strikes terribly their two under understanding until violence warring what when where white whoever wins with wrong younger - -2 Bernardo Jets Riff Sharks The by it led tragedy - -3 Maria Tony a can of stop - -4 to - -9 and the - -END - - -done_testing; - -sub capture { - my($cmd) = @_; - my $out = `$cmd`; - $out =~ s/\r//g; - return $out; -} diff --git a/challenge-082/paulo-custodio/Makefile b/challenge-082/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-082/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-082/paulo-custodio/perl/ch-1.pl b/challenge-082/paulo-custodio/perl/ch-1.pl index 5c83822a26..36f2083ee1 100644 --- a/challenge-082/paulo-custodio/perl/ch-1.pl +++ b/challenge-082/paulo-custodio/perl/ch-1.pl @@ -1,8 +1,8 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 082 # -# TASK #1 › Common Factors +# TASK #1 > Common Factors # Submitted by: Niels van Dijke # You are given 2 positive numbers $M and $N. # @@ -40,7 +40,7 @@ say "(", join(", ", @common), ")"; sub common_factors { my($a, $b) = @_; my @common; - for (my $i = 1; 2*$i <= $a || 2*$i <= $b; $i++) { + for (my $i = 1; $i <= $a || $i <= $b; $i++) { if (($a % $i)==0 && ($b % $i)==0) { push @common, $i; } diff --git a/challenge-082/paulo-custodio/perl/ch-2.pl b/challenge-082/paulo-custodio/perl/ch-2.pl index 40d7fa92b8..0ff83b3ce0 100644 --- a/challenge-082/paulo-custodio/perl/ch-2.pl +++ b/challenge-082/paulo-custodio/perl/ch-2.pl @@ -1,8 +1,8 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 082 # -# TASK #2 › Interleave String +# TASK #2 > Interleave String # Submitted by: Mohammad S Anwar # You are given 3 strings; $A, $B and $C. # diff --git a/challenge-082/paulo-custodio/python/ch-1.py b/challenge-082/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..c1eb31d194 --- /dev/null +++ b/challenge-082/paulo-custodio/python/ch-1.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +# Challenge 082 +# +# TASK #1 > Common Factors +# Submitted by: Niels van Dijke +# You are given 2 positive numbers $M and $N. +# +# Write a script to list all common factors of the given numbers. +# +# Example 1: +# Input: +# $M = 12 +# $N = 18 +# +# Output: +# (1, 2, 3, 6) +# +# Explanation: +# Factors of 12: 1, 2, 3, 4, 6 +# Factors of 18: 1, 2, 3, 6, 9 +# Example 2: +# Input: +# $M = 18 +# $N = 23 +# +# Output: +# (1) +# +# Explanation: +# Factors of 18: 1, 2, 3, 6, 9 +# Factors of 23: 1 + +import sys + +def get_common_factors(a, b): + factors = [] + i = 1 + while i <= a or i <= b: + if a%i==0 and b%i==0: + factors.append(i) + i += 1 + return factors + +factors = get_common_factors(int(sys.argv[1]), int(sys.argv[2])) +print("("+ ", ".join([str(x) for x in factors]) +" )") diff --git a/challenge-082/paulo-custodio/python/ch-2.py b/challenge-082/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..743f578782 --- /dev/null +++ b/challenge-082/paulo-custodio/python/ch-2.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +# Challenge 082 +# +# TASK #2 > Interleave String +# Submitted by: Mohammad S Anwar +# You are given 3 strings; $A, $B and $C. +# +# Write a script to check if $C is created by interleave $A and $B. +# +# Print 1 if check is success otherwise 0. +# +# Example 1: +# Input: +# $A = "XY" +# $B = "X" +# $C = "XXY" +# +# Output: 1 +# EXPLANATION +# "X" (from $B) + "XY" (from $A) = $C +# Example 2: +# Input: +# $A = "XXY" +# $B = "XXZ" +# $C = "XXXXZY" +# +# Output: 1 +# EXPLANATION +# "XX" (from $A) + "XXZ" (from $B) + "Y" (from $A) = $C +# Example 3: +# Input: +# $A = "YX" +# $B = "X" +# $C = "XXY" +# +# Output: 0 + +import sys + +def interleaved(a, b, c): + for i in range(len(a)+1): + if a[:i]+b+a[i:] == c: + return True + return False + +print(1 if interleaved(sys.argv[1], sys.argv[2], sys.argv[3]) else 0) diff --git a/challenge-082/paulo-custodio/t/test-1.yaml b/challenge-082/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..c4ddea94be --- /dev/null +++ b/challenge-082/paulo-custodio/t/test-1.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: 12 18 + input: + output: (1, 2, 3, 6) +- setup: + cleanup: + args: 18 23 + input: + output: (1) +- setup: + cleanup: + args: 5 5 + input: + output: (1, 5) diff --git a/challenge-082/paulo-custodio/t/test-2.yaml b/challenge-082/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..3115516fe0 --- /dev/null +++ b/challenge-082/paulo-custodio/t/test-2.yaml @@ -0,0 +1,20 @@ +- setup: + cleanup: + args: XY X XXY + input: + output: 1 +- setup: + cleanup: + args: XY Z XYZ + input: + output: 1 +- setup: + cleanup: + args: XXY XXZ XXXXZY + input: + output: 1 +- setup: + cleanup: + args: YX X XXY + input: + output: 0 diff --git a/challenge-082/paulo-custodio/test.pl b/challenge-082/paulo-custodio/test.pl deleted file mode 100644 index a14c8eda63..0000000000 --- a/challenge-082/paulo-custodio/test.pl +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/perl - -use Modern::Perl; -use Test::More; - -is capture("perl/ch-1.pl 12 18"), "(1, 2, 3, 6)\n"; -is capture("perl/ch-1.pl 18 23"), "(1)\n"; - -is capture("perl/ch-2.pl XY X XXY"), "1\n"; -is capture("perl/ch-2.pl XY Z XYZ"), "1\n"; -is capture("perl/ch-2.pl XXY XXZ XXXXZY"), "1\n"; -is capture("perl/ch-2.pl YX X XXY"), "0\n"; - -done_testing; - -sub capture { - my($cmd) = @_; - my $out = `$cmd`; - $out =~ s/[ \t\v\f\r]*\n/\n/g; - return $out; -} |
