aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2019-12-22 23:16:01 -0500
committerAdam Russell <ac.russell@live.com>2019-12-22 23:16:01 -0500
commitce9e5b7ef5706d875fd28aeb8c8cd054016d9f99 (patch)
tree946eb8bca8670ea4e3b964ba589fce007aa192f7
parentcb51051651bbd1532ddbf211c0200efd6ac8770c (diff)
downloadperlweeklychallenge-club-ce9e5b7ef5706d875fd28aeb8c8cd054016d9f99.tar.gz
perlweeklychallenge-club-ce9e5b7ef5706d875fd28aeb8c8cd054016d9f99.tar.bz2
perlweeklychallenge-club-ce9e5b7ef5706d875fd28aeb8c8cd054016d9f99.zip
deleted unnecessary files
-rw-r--r--challenge-038/adam-russell/perl/ch-1.pl50
-rw-r--r--challenge-038/adam-russell/perl/ch-2.pl79
2 files changed, 0 insertions, 129 deletions
diff --git a/challenge-038/adam-russell/perl/ch-1.pl b/challenge-038/adam-russell/perl/ch-1.pl
deleted file mode 100644
index 5baaad941b..0000000000
--- a/challenge-038/adam-russell/perl/ch-1.pl
+++ /dev/null
@@ -1,50 +0,0 @@
-use strict;
-use warnings;
-##
-# Create a script to accept a 7 digits number, where
-# the first number can only be 1 or 2. The second and
-# third digits can be anything 0-9. The fourth and
-# fifth digits corresponds to the month i.e. 01,02,03,...,11,12.
-# And the last 2 digits respresents the days in the
-# month i.e. 01,02,03,...,29,30,31. Your script should validate
-# if the given number is valid as per the rule and then
-# convert into human readable format date.
-# RULES
-# 1) If 1st digit is 1, then prepend 20 otherwise 19 to the
-# 2nd and 3rd digits to make it 4-digits year.
-# 2) The 4th and 5th digits together should be a valid month.
-# 3) The 6th and 7th digits together should be a valid day
-# for the above month.
-##
-use boolean;
-sub is_valid{
- my($x) = @_;
- $x =~ m/([1-2]{1})([0-9]{2})(0[1-9]{1}|1[012]{1})(0[1-9]{1}|1[012]{1}|2[0-9]{1})/;
- return $x, $1, $2, $3, $4;
-}
-
-sub transform{
- my($a, $b, $c, $d) = @_;
- if($a == 1){
- $a = "20$a";
- }
- else{
- $a = "19$b";
- }
- return "$a-$c-$d";
-}
-
-MAIN:{
- while(my $x = <DATA>){
- my ($valid, @fields) = is_valid($x);
- unless(!$valid){
- print transform(@fields) . "\n";
- }
- else{
- print "invalid: $x\n";
- }
- }
-}
-
-__DATA__
-2230120
diff --git a/challenge-038/adam-russell/perl/ch-2.pl b/challenge-038/adam-russell/perl/ch-2.pl
deleted file mode 100644
index f6f1615d5c..0000000000
--- a/challenge-038/adam-russell/perl/ch-2.pl
+++ /dev/null
@@ -1,79 +0,0 @@
-use strict;
-use warnings;
-##
-# Lets assume we have tiles with an alphabet (A..Z) printed on them.
-# Each tile has a value, e.g. A (1 point), B (4 points) etc. You are
-# allowed to draw 7 tiles from the lot randomly. Then try to form a
-# word using the 7 tiles with maximum points altogether. You don’t
-# have to use all the 7 tiles to make a word. You should try to use
-# as many tiles as possible to get the maximum points.
-##
-use constant DICTIONARY => "/usr/share/dict/words";
-use Readonly;
-Readonly::Hash my %CHAR_VALUES => (
- A => 1, B => 4, C => 5, D => 3, E => 2,
- F => 3, G => 1, H => 5, I => 1, J => 2,
- K => 10, L => 2, M => 5, N => 4, O => 5,
- P => 3, Q => 10, R => 2, S => 1, T => 5,
- U => 1, V => 2, W => 3, X => 1, Y => 2,
- Z => 1
-);
-
-Readonly::Hash my %CHAR_FREQUENCIES => (
- A => 8, B => 5, C => 4, D => 3, E => 9,
- F => 3, G => 3, H => 3, I => 5, J => 3,
- K => 2, L => 3, M => 4, N => 4, O => 3,
- P => 5, Q => 2, R => 3, S => 7, T => 5,
- U => 5, V => 3, W => 5, X => 2, Y => 5,
- Z => 5
-);
-
-sub draw7{
- my @letters;
- my @seven;
- for my $k (keys %CHAR_FREQUENCIES){
- push @letters, ($k) x $CHAR_FREQUENCIES{$k};
- }
- for(0..6){
- my $r = int(rand(@letters));
- push @seven, splice @letters, $r, 1;
- }
- return @seven;
-}
-
-sub find_max_score{
- my @seven = @_;
- my $max_score = 0;
- my $max_word;
- my $max_letters;
- open(WORDS, DICTIONARY);
- while(<WORDS>){
- chomp($_);
- my $word = uc($_);
- my $temp = $word;
- my @letters;
- for my $c (@seven){
- $word =~ s/(\Q$c\E)//;
- push @letters, $1 if $1;
- }
- if(!$word){
- my $sum = 0;
- map {$sum += $_} map{$CHAR_VALUES{$_}} @letters;
- if($max_score < $sum){
- $max_word = $temp;
- $max_letters = join(", " , @letters);
- $max_score = $sum;
- }
- }
- }
- close(WORDS);
- return $max_word, $max_letters, $max_score;
-}
-
-MAIN:{
- my @letters = draw7();
- print "LETTERS: " . join(", ", @letters) . "\n";
- my ($word, $letters, $score) = find_max_score(@letters);
- print "$word has a score of $score.\n";
- print "These letters were used: $letters.\n";
-}