LESEN + MALEN = HOBBYS
Die Aufgabe besteht darin, die Buchstaben durch Zahlen zu ersetzen damit folgende Gleichung stimmt:
LESEN
+ MALEN
= HOBBYS
Dabei gilt, dass eine Zahl für einen einzigen und keinen anderen Buchstaben steht! Wer möchte, setzt sich hin und probiert aus, bis es stimmt. Aber warum sollte dies nicht der Computer machen, der früher mal auf deutsch Rechner hieß. Hier ein unkommentiertes Programmbeispiel in der Sprache Perl.
#!c:\programme\perl\bin\perl.exe use strict; use warnings; use Time::Local; use POSIX qw(strftime); ##### V A R I A B L E N ##### my $DEBUG = 1; my $a=0; my $b=0; my $c=0; my $e=0; my $h=0; my $l=0; my $m=0; my $n=0; my $o=0; my $s=0; my $y=0; my $ergebnis=0; my $start_date=strftime('%Y%m%d %H:%M:%S',localtime()); &log("Start ... $start_date"); # ($a,$b,$e,$h,$l,$m,$n,$o,$s,$y) # H ist [1,..,9] alle anderen [0,..,9] for ($a=0;$a<10;$a++) { next if ( grep {$_ == $a} ("$b","$e","$h","$l","$m","$n","$o","$s","$y") ); for ($b=0;$b<10;$b++) { next if ( grep {$_ == $b} ("$a","$e","$h","$l","$m","$n","$o","$s","$y") ); for ($e=0;$e<10;$e++) { next if ( grep {$_ == $e} ("$a","$b","$h","$l","$m","$n","$o","$s","$y") ); for ($h=1;$h<10;$h++) { next if ( grep {$_ == $h} ("$a","$b","$e","$l","$m","$n","$o","$s","$y") ); for ($l=0;$l<10;$l++) { next if ( grep {$_ == $l} ("$a","$b","$e","$h","$m","$n","$o","$s","$y") ); for ($m=0;$m<10;$m++) { next if ( grep {$_ == $m} ("$a","$b","$e","$h","$l","$n","$o","$s","$y") ); for ($n=0;$n<10;$n++) { next if ( grep {$_ == $n} ("$a","$b","$e","$h","$l","$m","$o","$s","$y") ); for ($o=0;$o<10;$o++) { next if ( grep {$_ == $o} ("$a","$b","$e","$h","$l","$m","$n","$s","$y") ); for ($s=0;$s<10;$s++) { next if ( grep {$_ == $s} ("$a","$b","$e","$h","$l","$m","$n","$o","$y") ); for ($y=0;$y<10;$y++) { next if ( grep {$_ == $y} ("$a","$b","$e","$h","$l","$m","$n","$o","$s") ); $ergebnis=&pruefe_gleichung($a,$b,$e,$h,$l,$m,$n,$o,$s,$y); }; }; }; }; }; }; }; }; }; }; my $end_date=strftime('%Y%m%d %H:%M:%S',localtime()); &log("Ende ... $end_date"); exit 0; ##### SUB PRUEFE_GLEICHUNG ##### sub pruefe_gleichung() { my $a = $_[0]; my $b = $_[1]; my $e = $_[2]; my $h = $_[3]; my $l = $_[4]; my $m = $_[5]; my $n = $_[6]; my $o = $_[7]; my $s = $_[8]; my $y = $_[9]; my $str_summand1 = $l.$e.$s.$e.$n; my $str_summand2 = $m.$a.$l.$e.$n; my $str_summe = $h.$o.$b.$b.$y.$s; my $int_summand1 = int($str_summand1); my $int_summand2 = int($str_summand2); my $int_summe = int($str_summe); my $test_summe = $int_summand1 + $int_summand2; if ($test_summe == $int_summe) { &log("gefunden: $str_summand1"); &log(" + $str_summand2"); &log(" = $str_summe"); &log("H=$h O=$o B=$b B=$b Y=$y S=$s"); my $hb = $h + $b; my $bb = $b + $b; my $hy = $h + $y; my $hs = $h + $s; &log("N 51.".$o.$s.".".$hb.$bb.$hy); &log("E 06.".$y.$hy.".".$hb.$h.$hs); &log(" "); return 0; }; return 9; }; ##### SUB LOG ##### sub log() { my $text = $_[0]; my $LOGFILE = "lesen_plus_malen.log"; $text .="\n" unless ($text=~/\n$/); if ($DEBUG) { print $text; }else{ open(LOG,">>$LOGFILE"); print LOG $text; close(LOG); }; return 0; }; |
Programmausgabe:
20140601 00:24:08 Start ... 20140601 00:24:14 gefunden: 73834 20140601 00:24:14 + 21734 20140601 00:24:14 = 095568 20140601 00:24:14 H=0 O=9 B=5 B=5 Y=6 S=8 20140601 00:24:14 N 51.98.5106 20140601 00:24:14 E 06.66.508 20140601 00:24:14 20140601 00:25:02 gefunden: 37879 20140601 00:25:02 + 64379 20140601 00:25:02 = 102258 20140601 00:25:02 H=1 O=0 B=2 B=2 Y=5 S=8 20140601 00:25:02 N 51.08.346 20140601 00:25:02 E 06.56.319 20140601 00:25:02 20140601 00:25:26 gefunden: 12623 20140601 00:25:26 + 85123 20140601 00:25:26 = 097746 20140601 00:25:26 H=0 O=9 B=7 B=7 Y=4 S=6 20140601 00:25:26 N 51.96.7144 20140601 00:25:26 E 06.44.706 20140601 00:25:26 20140601 00:26:03 gefunden: 19492 20140601 00:26:03 + 37192 20140601 00:26:03 = 056684 20140601 00:26:03 H=0 O=5 B=6 B=6 Y=8 S=4 20140601 00:26:03 N 51.54.6128 20140601 00:26:03 E 06.88.604 20140601 00:26:03 20140601 00:26:05 gefunden: 32628 20140601 00:26:05 + 17328 20140601 00:26:05 = 049956 20140601 00:26:05 H=0 O=4 B=9 B=9 Y=5 S=6 20140601 00:26:05 N 51.46.9185 20140601 00:26:05 E 06.55.906 20140601 00:26:05 20140601 00:26:43 Ende ...