Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[b]my[/b] [navy]@array2[/navy] [teal]=[/teal] [b]map[/b] [teal]{[/teal] [navy]$p[/navy][teal]=[/teal][navy]$_[/navy][teal]||[/teal][navy]$p[/navy] [teal]}[/teal] [navy]@array[/navy][teal];[/teal]
my ($marker,@array2);
foreach (@array) {
if ($marker != 0) {
$marker = $_;
}
push(@array2,$marker);
}
print "@array2";
$p= $_ || $p
[gray]#!/usr/bin/perl -w[/gray]
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]strict[/green][red];[/red]
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]@array[/blue] = [red]([/red][fuchsia]100[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]200[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]100[/fuchsia],[fuchsia]40[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]0[/fuchsia],[fuchsia]50[/fuchsia][red])[/red][red];[/red]
[black][b]my[/b][/black] [red]([/red][blue]$i[/blue], [blue]$j[/blue], [blue]$k[/blue][red])[/red][red];[/red]
[black][b]my[/b][/black] [blue]$pnz[/blue]=[fuchsia]0[/fuchsia][red];[/red] [gray][i]# holds previous non-zero index[/i][/gray]
[olive][b]for[/b][/olive] [red]([/red][blue]$i[/blue]=[fuchsia]0[/fuchsia][red];[/red] [blue]$i[/blue] < [url=http://perldoc.perl.org/functions/scalar.html][black][b]scalar[/b][/black][/url] [blue]@array[/blue][red];[/red] [blue]$i[/blue]++[red])[/red] [red]{[/red]
[olive][b]if[/b][/olive] [red]([/red][blue]$array[/blue][red][[/red][blue]$i[/blue][red]][/red]==[fuchsia]0[/fuchsia][red])[/red] [red]{[/red]
[gray][i]# look forward to first non-zero[/i][/gray]
[olive][b]for[/b][/olive] [red]([/red][blue]$j[/blue]=[blue]$i[/blue][red];[/red] [blue]$j[/blue] < [red]([/red][black][b]scalar[/b][/black] [blue]@array[/blue] - [fuchsia]1[/fuchsia][red])[/red] && [blue]$array[/blue][red][[/red][blue]$j[/blue][red]][/red]==[fuchsia]0[/fuchsia] [red];[/red] [blue]$j[/blue]++[red])[/red] [red]{[/red]
[red]}[/red]
[gray][i]# print interpolated values[/i][/gray]
[olive][b]for[/b][/olive] [red]([/red][blue]$k[/blue]=[blue]$i[/blue][red];[/red] [blue]$k[/blue] < [blue]$j[/blue][red];[/red] [blue]$k[/blue]++[red])[/red] [red]{[/red]
[url=http://perldoc.perl.org/functions/printf.html][black][b]printf[/b][/black][/url] [red]"[/red][purple]%d[purple][b]\n[/b][/purple][/purple][red]"[/red], [blue]$array[/blue][red][[/red][blue]$pnz[/blue][red]][/red] + [red]([/red] [red]([/red][blue]$k[/blue]-[blue]$pnz[/blue][red])[/red]/[red]([/red][blue]$j[/blue]-[blue]$pnz[/blue][red])[/red] [blue]*[/blue] [red]([/red][blue]$[/blue]
[blue]array[/blue][red][[/red][blue]$j[/blue][red]][/red] - [blue]$array[/blue][red][[/red][blue]$pnz[/blue][red]][/red][red])[/red] [red])[/red][red];[/red]
[red]}[/red]
[blue]$i[/blue]=[blue]$j[/blue][red];[/red]
[red]}[/red]
[black][b]printf[/b][/black] [red]"[/red][purple]%d[purple][b]\n[/b][/purple][/purple][red]"[/red], [blue]$array[/blue][red][[/red][blue]$i[/blue][red]][/red][red];[/red]
[blue]$pnz[/blue]=[blue]$i[/blue][red];[/red]
[red]}[/red]
100
120
140
160
180
200
183
166
150
133
116
100
40
42
45
47
50