challenges

my solutions to various "programming challenge" problems
git clone https://wehaveforgeathome.hates.computer/challenges.git
Log | Files | Refs | LICENSE

commit c17c618b5188332317882def69e6837184906f1c
parent 276cf9136cd972b08a7937b34a9fc7abf44bce51
Author: Ryan Wolf <rwolf@borderstylo.com>
Date:   Mon, 18 Oct 2010 09:22:00 -0700

grepling problem 3, plus final text

Diffstat:
Mgreplin/README.md | 14++++++++++++++
Agreplin/level3.pl | 31+++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/greplin/README.md b/greplin/README.md @@ -61,3 +61,17 @@ the subsets would be Here is the list of numbers you should run your code on. The password is the number of subsets. In the above case the answer would be 4. + +The End + +---------------------------------------- + +Congratulations. You completed the challenge. Your completion code is. + +We'd love to talk to you - send your completion code, the code you wrote +during the challenge, and your resume to + +jobs+i+solved+the+challenge@greplin.com + +Even if you're not looking for a job, we'd love to hear what you thought +about the challenge. diff --git a/greplin/level3.pl b/greplin/level3.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use List::Util qw(sum); + +open(my $file, 'level3.csv'); +my $text = <$file>; +close($file); + +my @numbers = map(int, split(', ', $text)); + +my $l = scalar(@numbers); +my $p = 2 ** $l; + +my $count = 0; + +for (my $i = 1; $i < $p; $i++) { + my @set; + for (my $j = 0; $j < $l; $j++) { + push(@set, $numbers[$j]) if (($i >> $j) & 1); + } + if (scalar(@set) > 1) { + my $highest = pop(@set); + if ($highest == sum(@set)) { + $count++; + } + } +} + +print "$count\n";