diff options
| author | rir <rirans@comcast.net> | 2025-08-30 21:44:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-30 21:44:13 -0400 |
| commit | 551a847730016426f7f0c7c3f5772770cfb214f7 (patch) | |
| tree | 4f2465ff7d321458015023e8c07708cf4c1ef201 | |
| parent | 6d80a8bebd13b9d9e06494bdfa866906452413d6 (diff) | |
| parent | 1cda67fc152a1c71cf521ffe30c5f503959c81a1 (diff) | |
| download | perlweeklychallenge-club-551a847730016426f7f0c7c3f5772770cfb214f7.tar.gz perlweeklychallenge-club-551a847730016426f7f0c7c3f5772770cfb214f7.tar.bz2 perlweeklychallenge-club-551a847730016426f7f0c7c3f5772770cfb214f7.zip | |
Merge branch 'manwar:master' into work
35 files changed, 1029 insertions, 46 deletions
diff --git a/challenge-336/hvukman/lua/336_p1.lua b/challenge-336/hvukman/lua/336_p1.lua new file mode 100644 index 0000000000..76bc6ac291 --- /dev/null +++ b/challenge-336/hvukman/lua/336_p1.lua @@ -0,0 +1,51 @@ + +function gcd(x, y) + if (y == 0) then + return x + else + return gcd(y, x%y) + end +end + +function Equal_group(x) + + local set ={} + + + for i,v in ipairs(x) do + set[v]=true + end + local res = {} + for i,v in pairs(set) do + -- print(i) + local res_=0 + for _,w in ipairs(x) do + if i==w then + res_ =res_+ 1 + end + end + table.insert(res,res_) + end + + + local dummy=0 + local valid = true + for i=2,#res do + -- gcd for each pair + dummy= gcd(res[i-1],res[i]) + --print (dummy) + -- if gcd<=1 then failure + if dummy <= 1 then + valid = false + end + if valid == false then break end + end + + print(valid) +end + +local inputs = { {1,1,2,2,2,2},{1,1,1,2,2,2,3,3}, {5,5,5,5,5,5,7,7,7,7,7,7},{1,2,3,4},{8,8,9,9,10,10,11,11} } + +for i=1,#inputs do + Equal_group(inputs[i]) +end diff --git a/challenge-336/hvukman/lua/336_p2.lua b/challenge-336/hvukman/lua/336_p2.lua new file mode 100644 index 0000000000..7943f876d7 --- /dev/null +++ b/challenge-336/hvukman/lua/336_p2.lua @@ -0,0 +1,36 @@ +local scores = {"5","-2","4","C","D","9","+","+"}
+
+function Final_score(x)
+ local score = 0
+ local prev = {}
+ local res = {}
+
+ for i=1,#x do
+ if (tonumber(x[i])) then
+ table.insert(prev,x[i])
+ table.insert(res,x[i])
+ elseif scores[i]=="C" then
+ table.remove(prev)
+ table.remove(res)
+ elseif scores[i]=="D" then -- double previous score
+ local last = prev[#prev]
+ table.insert(res,last*2)
+ table.insert(prev,last*2)
+ elseif scores[i]=="+" then -- add last two scores
+ local last = prev[#prev]
+ local last2 = prev[#prev-1]
+ table.insert(res,last+last2)
+ table.insert(prev,last+last2)
+ end
+ end
+
+
+ for _,v in ipairs(res) do
+ print(v)
+ score= score + v
+ end
+
+ print("score ", score)
+end
+
+Final_score(scores)
\ No newline at end of file diff --git a/challenge-336/jeanluc2020/blog-1.txt b/challenge-336/jeanluc2020/blog-1.txt new file mode 100644 index 0000000000..f07491e7e0 --- /dev/null +++ b/challenge-336/jeanluc2020/blog-1.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-336-1.html diff --git a/challenge-336/jeanluc2020/blog-2.txt b/challenge-336/jeanluc2020/blog-2.txt new file mode 100644 index 0000000000..70dfb46300 --- /dev/null +++ b/challenge-336/jeanluc2020/blog-2.txt @@ -0,0 +1 @@ +http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-336-2.html diff --git a/challenge-336/jeanluc2020/perl/ch-1.pl b/challenge-336/jeanluc2020/perl/ch-1.pl new file mode 100755 index 0000000000..4b275b82d7 --- /dev/null +++ b/challenge-336/jeanluc2020/perl/ch-1.pl @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-336/#TASK1 +# +# Task 1: Equal Group +# =================== +# +# You are given an array of integers. +# +# Write a script to return true if the given array can be divided into one or +# more groups: each group must be of the same size as the others, with at least +# two members, and with all members having the same value. +# +## Example 1 +## +## Input: @ints = (1,1,2,2,2,2) +## Output: true +## +## Groups: (1,1), (2,2), (2,2) +# +# +## Example 2 +## +## Input: @ints = (1,1,1,2,2,2,3,3) +## Output: false +## +## Groups: (1,1,1), (2,2,2), (3,3) +# +# +## Example 3 +## +## Input: @ints = (5,5,5,5,5,5,7,7,7,7,7,7) +## Output: true +## +## Groups: (5,5,5,5,5,5), (7,7,7,7,7,7) +# +# +## Example 4 +## +## Input: @ints = (1,2,3,4) +## Output: false +# +############################################################ +## +## discussion +## +############################################################ +# +# You can create matching groups if all the numbers of integers of the same +# value are divisible by a common prime. So we check if we find a common prime +# factor: for each prime, check if it is a divisor of the number and count that, +# and if a prime happens to appear as often as there are distinct numbers in +# the input array, we can return "true". If in the end, this wasn't the case +# for any prime from our list, we return "false". + +use v5.36; +use List::Util qw(max); + +equal_group(1,1,2,2,2,2); +equal_group(1,1,1,2,2,2,3,3); +equal_group(5,5,5,5,5,5,7,7,7,7,7,7); +equal_group(1,2,3,4); + +sub equal_group( @ints ) { + say "Input: (" . join(", ", @ints) . ")"; + my $numbers; + foreach my $i (@ints) { + $numbers->{$i}++; + } + my $biggest = max( map { $numbers->{$_} } keys %$numbers ); + my @primes; + foreach my $n (2..$biggest) { + push @primes, $n if is_prime($n); + } + my $primes_found; + foreach my $n (keys %$numbers) { + foreach my $prime (@primes) { + $primes_found->{$prime}++ unless $numbers->{$n} % $prime; + } + } + foreach my $f (keys %$primes_found) { + return say "true" if $primes_found->{$f} == scalar(keys %$numbers); + } + return say "false"; +} + + +### From the solution of the weekly challenge 223: +sub is_prime { + my $num = shift; + return 0 if $num == 1; + my $divider = 2; + while($divider <= sqrt($num)) { + if(int($num/$divider) == $num/$divider) { + return 0; + } + $divider++; + } + return 1; +} + diff --git a/challenge-336/jeanluc2020/perl/ch-2.pl b/challenge-336/jeanluc2020/perl/ch-2.pl new file mode 100755 index 0000000000..cbb5ec72d7 --- /dev/null +++ b/challenge-336/jeanluc2020/perl/ch-2.pl @@ -0,0 +1,130 @@ +#!/usr/bin/env perl +# https://theweeklychallenge.org/blog/perl-weekly-challenge-336/#TASK2 +# +# Task 2: Final Score +# =================== +# +# You are given an array of scores by a team. +# +# Write a script to find the total score of the given team. The score can be +# any integer, +, C or D. The + adds the sum of previous two scores. The score +# C invalidates the previous score. The score D will double the previous score. +# +## Example 1 +## +## Input: @scores = ("5","2","C","D","+") +## Output: 30 +## +## Round 1: 5 +## Round 2: 5 + 2 +## Round 3: 5 (invalidate the previous score 2) +## Round 4: 5 + 10 (double the previous score 5) +## Round 5: 5 + 10 + 15 (sum of previous two scores) +## +## Total Scores: 30 +# +# +## Example 2 +## +## Input: @scores = ("5","-2","4","C","D","9","+","+") +## Output: 27 +## +## Round 1: 5 +## Round 2: 5 + (-2) +## Round 3: 5 + (-2) + 4 +## Round 4: 5 + (-2) (invalidate the previous score 4) +## Round 5: 5 + (-2) + (-4) (double the previous score -2) +## Round 6: 5 + (-2) + (-4) + 9 +## Round 7: 5 + (-2) + (-4) + 9 + 5 (sum of previous two scores) +## Round 8: 5 + (-2) + (-4) + 9 + 5 + 14 (sum of previous two scores) +## +## Total Scores: 27 +# +# +## Example 3 +## +## Input: @scores = ("7","D","D","C","+","3") +## Output: 45 +## +## Round 1: 7 +## Round 2: 7 + 14 (double the previous score 7) +## Round 3: 7 + 14 + 28 (double the previous score 14) +## Round 4: 7 + 14 (invalidate the previous score 28) +## Round 5: 7 + 14 + 21 (sum of previous two scores) +## Round 6: 7 + 14 + 21 + 3 +## +## Total Scores: 45 +# +# +## Example 4 +## +## Input: @scores = ("-5","-10","+","D","C","+") +## Output: -55 +## +## Round 1: (-5) +## Round 2: (-5) + (-10) +## Round 3: (-5) + (-10) + (-15) (sum of previous two scores) +## Round 4: (-5) + (-10) + (-15) + (-30) (double the previous score -15) +## Round 5: (-5) + (-10) + (-15) (invalidate the previous score -30) +## Round 6: (-5) + (-10) + (-15) + (-25) (sum of previous two scores) +## +## Total Scores: -55 +# +# +## Example 5 +## +## Input: @scores = ("3","6","+","D","C","8","+","D","-2","C","+") +## Output: 128 +## +## Round 1: 3 +## Round 2: 3 + 6 +## Round 3: 3 + 6 + 9 (sum of previous two scores) +## Round 4: 3 + 6 + 9 + 18 (double the previous score 9) +## Round 5: 3 + 6 + 9 (invalidate the previous score 18) +## Round 6: 3 + 6 + 9 + 8 +## Round 7: 3 + 6 + 9 + 8 + 17 (sum of previous two scores) +## Round 8: 3 + 6 + 9 + 8 + 17 + 34 (double the previous score 17) +## Round 9: 3 + 6 + 9 + 8 + 17 + 34 + (-2) +## Round 10: 3 + 6 + 9 + 8 + 17 + 34 (invalidate the previous score -2) +## Round 11: 3 + 6 + 9 + 8 + 17 + 34 + 51 (sum of previous two scores) +## +## Total Scores: 128 +# +############################################################ +## +## discussion +## +############################################################ +# +# For each element in the scores, we add or remove an element from +# a stack: either push the double of the last element on the stack +# in case of "D", or the sum of the last two elements on the stack +# in case of "+", or remove the last element of the stack for a "C", +# or push the element otherwise (as then it's a number). In the end, +# we just return the sum of all elements on the stack. + +use v5.36; +use List::Util qw(sum); + +final_score("5","2","C","D","+"); +final_score("5","-2","4","C","D","9","+","+"); +final_score("7","D","D","C","+","3"); +final_score("-5","-10","+","D","C","+"); +final_score("3","6","+","D","C","8","+","D","-2","C","+"); + +sub final_score(@scores) { + say "Input: (\"" . join("\", \"", @scores) . "\")"; + my @stack = (); + foreach my $s (@scores) { + if($s eq "D") { + push @stack, 2 * $stack[-1]; + } elsif ($s eq "C") { + pop @stack; + } elsif ($s eq "+") { + push @stack, $stack[-1] + $stack[-2]; + } else { + push @stack, $s; + } + } + say "Output: " . sum(@stack); +} diff --git a/challenge-336/mattneleigh/perl/ch-1.pl b/challenge-336/mattneleigh/perl/ch-1.pl new file mode 100755 index 0000000000..d2dc9b5e2b --- /dev/null +++ b/challenge-336/mattneleigh/perl/ch-1.pl @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use English; + +################################################################################ +# Begin main execution +################################################################################ + +my @integer_lists = ( + [ 1, 1, 2, 2, 2, 2 ], + [ 1, 1, 1, 2, 2, 2, 3, 3 ], + [ 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7 ], + [ 1, 2, 3, 4 ], + [ 8, 8, 9, 9, 10, 10, 11, 11 ] +); + +print("\n"); +foreach my $integer_list (@integer_lists){ + printf( + "Input: \@ints = (%s)\nOutput: %s\n\n", + join(", ", @{$integer_list}), + array_evenly_regroupable(@{$integer_list}) ? + "true" + : + "false" + ); +} + +exit(0); +################################################################################ +# End main execution; subroutines follow +################################################################################ + + + +################################################################################ +# Given an array of integers, determine whether they can be divided into groups +# in which all members of each group has the same value, the groups have the +# same number of members, and each group has at least two members +# Takes one argument: +# * The array of integers to examine (e.g. (8, 8, 9, 9, 10, 10, 11, 11) ) +# Returns: +# * 0 if the array does not meet the criteria described above +# * 1 if the array meets the criteria described above (as would be the case in +# the example provided) +################################################################################ +sub array_evenly_regroupable{ + use List::Util qw(min); + + my %count_table; + my @counts; + my $min; + + # Count the instances of each number + foreach(@ARG){ + $count_table{$_}++; + } + + # Make a list of counts and find the smallest + @counts = map($count_table{$_}, keys(%count_table)); + $min = min(@counts); + + # Make sure the smallest count is at least 2 + return(0) + unless($min > 1); + + # Return 0 if any count isn't evenly divisible + # by the minimum count + foreach my $count (@counts){ + return(0) + if($count % $min); + } + + # Got here- the array met our criteria; + # return 1 + return(1); + +} + + + diff --git a/challenge-336/mattneleigh/perl/ch-2.pl b/challenge-336/mattneleigh/perl/ch-2.pl new file mode 100755 index 0000000000..94a2b1b0d8 --- /dev/null +++ b/challenge-336/mattneleigh/perl/ch-2.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use English; + +################################################################################ +# Begin main execution +################################################################################ + +my @score_sets = ( + [ "5", "2", "C", "D", "+" ], + [ "5", "-2", "4", "C", "D", "9", "+", "+" ], + [ "7", "D", "D", "C", "+", "3" ], + [ "-5", "-10", "+", "D", "C", "+" ], + [ "3", "6", "+", "D", "C", "8", "+", "D", "-2", "C", "+" ] +); + +print("\n"); +foreach my $scores (@score_sets){ + printf( + "Input: \@scores = (%s)\nOutput: %d\n\n", + join( + ", ", + map( + "\"" . $_ . "\"", + @{$scores} + ) + ), + evaluate_scores(@{$scores}) + ); +} + +exit(0); +################################################################################ +# End main execution; subroutines follow +################################################################################ + + + +################################################################################ +# Given a list of scores and instructional codes, evaluate the list and +# determine the resulting total score; scores may consist of the following: +# * + - An instruction to add the last two scores in the list together and +# place the result at the end of the list, leaving the two added scores +# in place (i.e. (...5, 10) --> (...5, 10, 15) ) +# * C - An instruction to invalidate the last score and remove it from the +# list (i.e. (...5, 10) --> (...5) ) +# * D - An instruction to double the last score and place it at the end of the +# list, leaving the value that was doubled in place as well (i.e. +# (...5, 10) --> (...5, 10, 20) +# * An integer value to be added to the list +# All values in the list will be summed after processing, and the resulting +# value returned +# Takes one argument: +# * The list of scores and instructions to examine (e.g. +# ("3", "6", "+", "D", "C", "8", "+", "D", "-2", "C", "+") ) +# Returns: +# * The result of processing the scores and instructions as described above +# (e.g. 128) +################################################################################ +sub evaluate_scores{ + use List::Util qw(sum); + + my @scores; + + # Loop over every score or embedded opcode + foreach my $score (@ARG){ + if($score eq '+'){ + # Sum opcode- add the sum of the last two + # scores to the list + push(@scores, $scores[-1] + $scores[-2]); + } elsif($score eq 'C'){ + # Cancel opcode- remove the last score from + # the list + pop(@scores); + } elsif($score eq 'D'){ + # Double opcode- double the last score and + # add the result to the list + push(@scores, $scores[-1] * 2); + } else{ + # A score- add it to the list + push(@scores, $score); + } + } + + # Return the sum of the scores + return(sum(@scores)); + +} + + + diff --git a/challenge-336/peter-meszaros/perl/ch-1.pl b/challenge-336/peter-meszaros/perl/ch-1.pl new file mode 100755 index 0000000000..1442513de5 --- /dev/null +++ b/challenge-336/peter-meszaros/perl/ch-1.pl @@ -0,0 +1,92 @@ +#!/usr/bin/env perl +# +=head1 Task 1: Equal Group + +Submitted by: Mohammad Sajid Anwar + +You are given an array of integers. + +Write a script to return true if the given array can be divided into one or +more groups: each group must be of the same size as the others, with at least +two members, and with all members having the same value. + +=head2 Example 1 + + Input: @ints = (1,1,2,2,2,2) + Output: true + + Groups: (1,1), (2,2), (2,2) + +=head2 Example 2 + + Input: @ints = (1,1,1,2,2,2,3,3) + Output: false + + Groups: (1,1,1), (2,2,2), (3,3) + +=head2 Example 3 + + Input: @ints = (5,5,5,5,5,5,7,7,7,7,7,7) + Output: true + + Groups: (5,5,5,5,5,5), (7,7,7,7,7,7) + +=head2 Example 4 + + Input: @ints = (1,2,3,4) + Output: false + +=head2 Example 5 + + Input: @ints = (8,8,9,9,10,10,11,11) + Output: true + + Groups: (8,8), (9,9), (10,10), (11,11) + +=cut + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; + +my $cases = [ + [[1,1,2,2,2,2], 1, "Example 1"], + [[1,1,1,2,2,2,3,3], 0, "Example 2"], + [[5,5,5,5,5,5,7,7,7,7,7,7], 1, "Example 3"], + [[1,2,3,4], 0, "Example 4"], + [[8,8,9,9,10,10,11,11], 1, "Example 5"], +]; + +sub equal_group +{ + my ($ints) = @_; + + my %count; + $count{$_}++ for @$ints; + my @values = values %count; + my $min = $values[0]; + for my $v (@values[1 .. $#values]) { + $min = $v if $v < $min; + } + return 0 if $min < 2; + + for my $size (2 .. $min) { + my $ok = 1; + for my $v (@values) { + if ($v % $size != 0) { + $ok = 0; + last; + } + } + return 1 if $ok; + } + return 0; +} + +for (@$cases) { + is(equal_group($_->[0]), $_->[1], $_->[2]); +} +done_testing(); + +exit 0; diff --git a/challenge-336/peter-meszaros/perl/ch-2.pl b/challenge-336/peter-meszaros/perl/ch-2.pl new file mode 100755 index 0000000000..1187ace468 --- /dev/null +++ b/challenge-336/peter-meszaros/perl/ch-2.pl @@ -0,0 +1,128 @@ +#!/usr/bin/env perl +# +=head1 Task 2: Final Score + +Submitted by: Mohammad Sajid Anwar + +You are given an array of scores by a team. + +Write a script to find the total score of the given team. The score can be any +integer, +, C or D. The + adds the sum of previous two scores. The score C +invalidates the previous score. The score D will double the previous score. + +=head2 Example 1 + + Input: @scores = ("5","2","C","D","+") + Output: 30 + + Round 1: 5 + Round 2: 5 + 2 + Round 3: 5 (invalidate the previous score 2) + Round 4: 5 + 10 (double the previous score 5) + Round 5: 5 + 10 + 15 (sum of previous two scores) + + Total Scores: 30 + +=head2 Example 2 + + Input: @scores = ("5","-2","4","C","D","9","+","+") + Output: 27 + + Round 1: 5 + Round 2: 5 + (-2) + Round 3: 5 + (-2) + 4 + Round 4: 5 + (-2) (invalidate the previous score 4) + Round 5: 5 + (-2) + (-4) (double the previous score -2) + Round 6: 5 + (-2) + (-4) + 9 + Round 7: 5 + (-2) + (-4) + 9 + 5 (sum of previous two scores) + Round 8: 5 + (-2) + (-4) + 9 + 5 + 14 (sum of previous two scores) + + Total Scores: 27 + +=head2 Example 3 + + Input: @scores = ("7","D","D","C","+","3") + Output: 45 + + Round 1: 7 + Round 2: 7 + 14 (double the previous score 7) + Round 3: 7 + 14 + 28 (double the previous score 14) + Round 4: 7 + 14 (invalidate the previous score 28) + Round 5: 7 + 14 + 21 (sum of previous two scores) + Round 6: 7 + 14 + 21 + 3 + + Total Scores: 45 + +=head2 Example 4 + + Input: @scores = ("-5","-10","+","D","C","+") + Output: -55 + + Round 1: (-5) + Round 2: (-5) + (-10) + Round 3: (-5) + (-10) + (-15) (sum of previous two scores) + Round 4: (-5) + (-10) + (-15) + (-30) (double the previous score -15) + Round 5: (-5) + (-10) + (-15) (invalidate the previous score -30) + Round 6: (-5) + (-10) + (-15) + (-25) (sum of previous two scores) + + Total Scores: -55 + +=head2 Example 5 + + Input: @scores = ("3","6","+","D","C","8","+","D","-2","C","+") + Output: 128 + + Round 1: 3 + Round 2: 3 + 6 + Round 3: 3 + 6 + 9 (sum of previous two scores) + Round 4: 3 + 6 + 9 + 18 (double the previous score 9) + Round 5: 3 + 6 + 9 (invalidate the previous score 18) + Round 6: 3 + 6 + 9 + 8 + Round 7: 3 + 6 + 9 + 8 + 17 (sum of previous two scores) + Round 8: 3 + 6 + 9 + 8 + 17 + 34 (double the previous score 17) + Round 9: 3 + 6 + 9 + 8 + 17 + 34 + (-2) + Round 10: 3 + 6 + 9 + 8 + 17 + 34 (invalidate the previous score -2) + Round 11: 3 + 6 + 9 + 8 + 17 + 34 + 51 (sum of previous two scores) + + Total Scores: 128 + +=cut + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; + +my $cases = [ + [["5", "2", "C", "D", "+"], 30, "Example 1"], + [["5", "-2", "4", "C", "D", "9", "+", "+"], 27, "Example 2"], + [["7", "D", "D", "C", "+", "3"], 45, "Example 3"], + [["-5","-10", "+", "D", "C", "+"], -55, "Example 4"], + [["3", "6", "+", "D", "C", "8", "+", "D", "-2", "C", "+"], 128, "Example 5"], +]; + +sub final_score +{ + my ($scores) = @_; + + my @stack; + for my $s (@$scores) { + if ($s eq 'C') { + pop @stack; + } elsif ($s eq 'D') { + push @stack, 2 * $stack[-1]; + } elsif ($s eq '+') { + push @stack, $stack[-1] + $stack[-2]; + } else { + push @stack, $s; + } + } + return eval join '+', @stack; +} + +for (@$cases) { + is(final_score($_->[0]), $_->[1], $_->[2]); +} +done_testing(); + +exit 0; diff --git a/challenge-336/peter-meszaros/tcl/ch-1.tcl b/challenge-336/peter-meszaros/tcl/ch-1.tcl new file mode 100755 index 0000000000..574a69045d --- /dev/null +++ b/challenge-336/peter-meszaros/tcl/ch-1.tcl @@ -0,0 +1,95 @@ +#!/usr/bin/env tclsh +# +# Submitted by: Mohammad Sajid Anwar +# +# You are given an array of integers. +# +# Write a script to return true if the given array can be divided into one or +# more groups: each group must be of the same size as the others, with at least +# two members, and with all members having the same value. +# +# Example 1 +# +# Input: @ints = (1,1,2,2,2,2) +# Output: true +# +# Groups: (1,1), (2,2), (2,2) +# +# Example 2 +# +# Input: @ints = (1,1,1,2,2,2,3,3) +# Output: false +# +# Groups: (1,1,1), (2,2,2), (3,3) +# +# Example 3 +# +# Input: @ints = (5,5,5,5,5,5,7,7,7,7,7,7) +# Output: true +# +# Groups: (5,5,5,5,5,5), (7,7,7,7,7,7) +# +# Example 4 +# +# Input: @ints = (1,2,3,4) +# Output: false +# +# Example 5 +# +# Input: @ints = (8,8,9,9,10,10,11,11) +# Output: true +# +# Groups: (8,8), (9,9), (10,10), (11,11) +# + +package require tcltest + +set cases { + {{1 1 2 2 2 2} 1 "Example 1"} + {{1 1 1 2 2 2 3 3} 0 "Example 2"} + {{5 5 5 5 5 5 7 7 7 7 7 7} 1 "Example 3"} + {{1 2 3 4} 0 "Example 4"} + {{8 8 9 9 10 10 11 11} 1 "Example 5"} +} + +proc equal_group {ints} { + array set count {} + foreach i $ints { + incr count($i) + } + foreach key [lsort -integer [array names count]] { + lappend values $count($key) + } + set min [lindex $v |
