Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Map-range/Perl/map-range.pl
Normal file
12
Task/Map-range/Perl/map-range.pl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict ;
|
||||
|
||||
sub mapValue {
|
||||
my ( $range1 , $range2 , $number ) = @_ ;
|
||||
return ( $range2->[ 0 ] +
|
||||
(( $number - $range1->[ 0 ] ) * ( $range2->[ 1 ] - $range2->[ 0 ] ) ) / ( $range1->[ -1 ]
|
||||
- $range1->[ 0 ] ) ) ;
|
||||
}
|
||||
my @numbers = 0..10 ;
|
||||
my @interval = ( -1 , 0 ) ;
|
||||
print "The mapped value for $_ is " . mapValue( \@numbers , \@interval , $_ ) . " !\n" foreach @numbers ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue