In perl language. (a) fibbing.pl Write a file that writes the first 1000 values
ID: 3666246 • Letter: I
Question
In perl language.
(a) fibbing.pl Write a file that writes the first 1000 values of the Fibonacci sequence in a newline delimited file, output.txt.
(b) sortEightGold.pl Write a perl script that generates two files: input.txt and output.txt. The input.txt file should contain 1000 sets of 8 16bit signed numbers represented in an integer format. Each number should be separated by a space and each set separated by a newline. The output.txt file should be in the same format, but contain sorted sequences. The left most number should be the greatest and the right most should be the least.
(c) lsifGold.pl Write a perl script that generates two files: input.txt and output.txt. The input.txt file should contain 1000 8bit unsigned numbers represented in an integer format. Each number should be separated by a newline. The output.txt file shoulf contain 1000 8bit unsigned numbers represented in an integer format corresponding to the convolution of input.txt by the sequence (15, 63 , 100, 63 ,15) and then divide by 256. The value on line “i” of the output file should represent the convolution of lines “i-5:i-1”. You may assume that negative indices are 0-valued.
Explanation / Answer
a)
#!usr/bin/local/perl
$n=<>;
$f= 0;
$s = 1;
for ( $i = 0 ; $i < $n ; $i++ )
{
if($i<= 1 )
{
$next=$i;
}
else
{
$next = $f + $s;
$f = $s;
$s = $next;
}
print(" the fibonacci series:$next ");
}
b)
c)
#!/usr/bin/perl
#use strict;
use warnings;
@array = (1..100);
$number = <STDIN>;
$low = 0;
$high = $#array;
while($low < $high){
print "Searcing $low ---- $high ";
$mid = $low + ($high - $low)/2;
if($array[$mid] == $number){
print "Found in index:" . $mid;
last;
}
elsif($array[$mid] < $number){
$low = $mid + 1;
}
else{
$high = $mid - 1;
}
}