now, i hope there's no problem up to here; but what i need is that function in reverse (yes... i have slight problems with mathematics...), that means that the new function should get the $carry and $out of longdive() and reasult with $in, but not by just $out*222+$carry, because i work with numbers that have thousands of digits... Thanks in advance.#!/usr/bin/perl -w use strict; sub longdiv($) { # take the parameter passed into the sub and store in $in my $in = shift; # initialise $carry and $out variables my $carry = 0; my $out = ''; # for each position in the $in string for (my $i = 0; $i < length($in); $i++) { # take a single character at that position and store in $numer +ator my $numerator = substr($in, $i, 3); # add $carry to it $numerator += $carry; # $carry equals $numerator mod 222 $carry = ($numerator % 222); # append the integer division of $numerator by two to the end +of the $out variable $out .= int($numerator / 222); } # return the result return $out; } # call the function and print the output print longdiv2("15000000") . "\n";
In reply to Reversed long division by Smoke
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |