".renderExpression($a, $b)."
refresh "; /*calcolo la lunghezza del pattern per ogni numero*/ function decToBin($dec,$j) { $i = 0; $l=0; $spazi=2; do { if ($dec % 2) { $spazi=2; $l++; $conta++; } else { $spazi=1; } $dec = (int) ($dec /2); $i++; } while ($dec > 0); $output[2]=$conta; $output[3]=$spazi; return $output; } /*creo il numero con il pattern*/ function decToBin2($dec,$j,$x) { //posso scegliere una qualsiasi stringa di caratteri ASCII $pattern = "2+2=5?1+4=3?6+2=7?1+1=3?1+1=5?3+2=6?"; //taglio il pattern e lo inverto $pattern=substr($pattern, 0, $x); $pattern=strrev($pattern); //inizializzo $output[1] = " "; $i = 0; $l=0; $spazi=2; //creo la stringa do { if ($dec % 2) { $output[1] {2-$i }= $pattern { $l+$j }; $spazi=2; $l++; $conta++; } else { $output[1] {2-$i } = " "; $spazi=1; } $dec = (int) ($dec /2); $i++; } while ($dec > 0); //array di output $output[2]=$conta; $output[3]=$spazi; $output[1]=strrev($output[1]); return $output; } /*genero la stringa*/ function renderExpression($a, $b) { //ad ogni numero corrisponde una codifica per renderizzarne la forma $number = array ( array ( 7, 5, 5, 5, 7 ), array ( 7, 2, 2, 6, 2 ), array ( 7, 4, 7, 1, 7 ), array ( 7, 1, 7, 1, 7 ), array ( 1, 1, 7, 5, 4 ), array ( 7, 1, 7, 4, 7 ), array ( 7, 5, 7, 4, 7 ), array ( 1, 1, 1, 1, 7 ), array ( 7, 5, 7, 5, 7 ), array ( 7, 1, 7, 5, 7 ) ); $plus = array ( 0, 2, 7, 2, 0 ); $eq = array ( 0, 7, 0, 7, 0 ); //inizializzo le lunghezze $x=0; $y=0; $w=0; $z=0; $t=0; $s=0; //calcolo il risultato $c=$a+$b; //controllo che sia di una o due cifre if(strlen($c)==2){ $d=substr($c,0,1); $e=substr($c,1,2); } //calcolo le lunghezze for ($line = 0; $line < 5; $line++) { $output1=decToBin($number[$a][$line],$x); $x=$x+$output1[2]; $output2=decToBin($number[$b][$line],$y); $y=$y+$output2[2]; $output3=decToBin($plus[$line],$w,$p); $w=$w+$output3[2]; $output4=decToBin($eq[$line],$z,$q); $z=$z+$output4[2]; if(strlen($c)==1){ $output5=decToBin($number[$c][$line],$t); $t=$t+$output5[2];} else{ $output5=decToBin($number[$d][$line],$t); $t=$t+$output5[2]; $output6=decToBin($number[$e][$line],$s); $s=$s+$output6[2]; } } $v=$x; $u=$y; $p=$w; $q=$z; $m=$t; $n=$s; $x=0; $y=0; $w=0; $z=0; $t=0; $s=0; //genero le stringhe for ($line = 0; $line < 5; $line++) { $output1=decToBin2($number[$a][$line],$x,$v); $x=$x+$output1[2]; $output2=decToBin2($number[$b][$line],$y,$u); $y=$y+$output2[2]; $output3=decToBin2($plus[$line],$w,$p); $w=$w+$output3[2]; $output4=decToBin2($eq[$line],$z,$q); $z=$z+$output4[2]; if(strlen($c)==1){ $output5=decToBin2($number[$c][$line],$t,$m); $t=$t+$output5[2]; $stringa .= $output5[1] . " ".$output4[1] . " " .$output2[1]. " " . $output3[1] . " " . $output1[1] . "\n"; } else{ $output5=decToBin2($number[$d][$line],$t,$m); $t=$t+$output5[2]; $output6=decToBin2($number[$e][$line],$s,$n); $s=$s+$output6[2]; $stringa .= $output6[1] . " ".$output5[1] . " ".$output4[1] . " " .$output2[1]. " " . $output3[1] . " " . $output1[1] . "\n"; } //inverto la stringa $stringa = str_replace("0", " ", $stringa); } $stringa=strrev($stringa); return $stringa; } ?>