Skip to content

Commit

Permalink
- Added solutions by Cheok-Yin Fung.
Browse files Browse the repository at this point in the history
  • Loading branch information
manwar committed Jan 29, 2020
1 parent 08974ae commit 892530a
Show file tree
Hide file tree
Showing 14 changed files with 1,000 additions and 903 deletions.
1 change: 1 addition & 0 deletions challenge-044/cheok-yin-fung/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Solutions by Cheok-Yin Fung.
50 changes: 50 additions & 0 deletions challenge-044/cheok-yin-fung/perl/ch-1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/perl -w
use strict;
use integer;

my @digits = 1..9;

sub expression {
}


my @poweroft = (6561,2187, 729, 243, 81, 27, 9, 3, 1);
for my $i (1..6560) {

my @ooo = (0,0,0,0,0,0,0,0); # 0 -> conjuction , 1 -> plus , 2 -> minus
for my $j (0..7) {
$ooo[$j] = int($i % $poweroft[$j]) / int($poweroft[$j+1]) ;
}


my @objects = (1,0,0,0,0,0,0,0,0);
my $objectindex = 0;
for my $j (0..7) {
if ($ooo[$j] == 0) {
$objects[$objectindex] = $objects[$objectindex]*10 + $digits[$j+1];
} else {$objectindex++; $objects[$objectindex] = $digits[$j+1];}
}

my $result = $objects[0];
$objectindex = 0;

for my $j (0..7) {
if ($ooo[$j] == 1) {$objectindex++; $result += $objects[$objectindex]; }
if ($ooo[$j] == 2) {$objectindex++; $result -= $objects[$objectindex]; }
}



if ($result == 100) {


print $digits[0];
for my $j (0..7) {
if ($ooo[$j]==1 ) {print "+"; }
if ($ooo[$j]==2 ) {print "-"; }
print $digits[$j+1];
}
print "\n";
}
}

22 changes: 22 additions & 0 deletions challenge-044/cheok-yin-fung/perl/ch-2.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#/usr/bin/perl -w
use integer;
use strict;

sub min {
if ($_[0] < $_[1]) {
$_[0];
} else {
$_[1];
}

}

my @t = (0, 0, 1);

for my $k (3..200) {
if ($k % 2 == 0) {$t[$k] = 1+ &min( $t[$k/2] , $t[$k-1])}
else {$t[$k] = $t[$k-1]+1;}
}

print $t[200], "\n";

1 change: 1 addition & 0 deletions members.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"bwva" : "Bruce Van Allen",
"bruno-ramos" : "Bruno Ramos",
"burkhard-nickels" : "Burkhard Nickels",
"cheok-yin-fung" : "Cheok-Yin Fung",
"cliveholloway" : "Clive Holloway",
"colin-crain" : "Colin Crain",
"creewick" : "Creewick",
Expand Down
Loading

0 comments on commit 892530a

Please sign in to comment.