forked from manwar/perlweeklychallenge-club
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added solutions by Cheok-Yin Fung.
- Loading branch information
Showing
14 changed files
with
1,000 additions
and
903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Solutions by Cheok-Yin Fung. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.