summaryrefslogtreecommitdiff
path: root/noncore/games/wordgame/calcdist
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (side-by-side diff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/games/wordgame/calcdist
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'noncore/games/wordgame/calcdist') (more/less context) (ignore whitespace changes)
-rwxr-xr-xnoncore/games/wordgame/calcdist27
1 files changed, 27 insertions, 0 deletions
diff --git a/noncore/games/wordgame/calcdist b/noncore/games/wordgame/calcdist
new file mode 100755
index 0000000..faf31f1
--- a/dev/null
+++ b/noncore/games/wordgame/calcdist
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# Usage: cat dictionaries | grep -v '[^a-z]' | calcdist n score
+#
+# Given a lot of words, find an appropriate distribution
+# into n tiles with tile values proportional to the square root
+# of the ratio of score to the tile's frequency.
+
+$n = shift;
+$score = shift;
+
+while (<>) {
+ chomp;
+ for $c ( split "", $_ ) {
+ $freq{$c}++;
+ $t++;
+ }
+}
+
+for $c ( sort { $freq{$a} <=> $freq{$b} } keys %freq ) {
+ #print "$c: $freq{$c}\n";
+ $need = int($freq{$c}*$n/$t+0.5) || 1;
+ $value = int(sqrt($score/($freq{$c}*$n/$t))+0.5) || 1;
+ $t -= $freq{$c};
+ $n -= $need;
+ print "$need $c $value\n";
+}