Permalink
Browse files

start working on actual puzzle generation

  • Loading branch information...
1 parent 06fd81b commit 2005de13f831f5b445c33380644fdeb82dd7d741 @mjdominus committed May 23, 2010
Showing with 32 additions and 0 deletions.
  1. +32 −0 mathpuzzle.pl
View
@@ -5,6 +5,22 @@
*2 +8 /2 -7 +3
+4 *3 -9 /3 -1
);
+
+my @pats = ([qw(a b * x /)],
+ [qw(a * cb x /)],
+ [qw(* a b x /)],
+ [qw(a * b / x)],
+ [qw(* a b / x)],
+ [qw(* a / b x)],
+ );
+
+my $bigC = randc(1/2, 3, 4);
+for my $row (qw(A B C D)) {
+ my $c = randc(2/3, 2, $bigC);
+ $bigC = 2 if $c == $bigC;
+ my $pat = randa(@pats);
+}
+
for (@vals) { tr{*}{×}; tr{/}{÷}; }
for my $letter (qw(A B C D)) {
for my $number (1..5) {
@@ -18,3 +34,19 @@
s/([A-D][1-5])/$t{$1}/g;
print;
}
+
+sub randc {
+ my ($p, $a, $b) = @_;
+ return rand() < $p ? $a : $b;
+}
+
+sub randn {
+ my $n = shift;
+ return int(rand($n));
+}
+
+sub randa {
+ my @a = @_;
+ my $n = randn(scalar @a);
+ return $a[$n];
+}

0 comments on commit 2005de1

Please sign in to comment.