10 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl -w
use strict;
my($v,@array, $i, %assarray, $index);
srand;
$v=0;
while ($v++ < 10)
{
@array = split (" ",rand(100));
printf("%d %d\n", $v, @array);
}
for ($i=0;$i <= $#array;$i++)
{
if(!defined($assarray{$array[$i]}))
{
$assarray{$array[$i]} = 1;
}
else
{
$assarray{$array[$i]}++;
}
}
foreach $index (keys %assarray)
{
printf ("%d %d %d\n",$index, $assarray{$index}, length($index));
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/perl -w
use strict;
my ($v,@array, $i, %assarray, $index);
srand;
$v=0;
while ($v++ < 10){
push (@array, int (rand (100)) + 1);
printf ("%d) %d\n", $v, @array);
}
foreach $i (0..$#array) {
$assarray{"$i"}++;
}
print "Anzahl der Zahlen:\n";
print "-" x 60;
print "\n";
foreach $index (keys %assarray){
printf "%d %d %d\n", $index, $assarray{$index}, length($index);
}
@array = split (" ",rand(100));
push (@array, int (rand (100)) + 1);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl -w
use strict;
my @zufallszahlen;
#zufallszahlen hinzufügen
for (0..9) {
push @zufallszahlen, int(rand(101));
#print $_+1 .") $zufallszahlen[$_]\n";
}
print "-"x30 ."\n";
#zahlen abgleichen und ausgeben
for my $curr (@zufallszahlen) {
my $i = 0;
for(@zufallszahlen) {
$i++ if ($curr == $_);
}
print "$curr kommt $i mal vor.\n";
}
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/perl
use strict;
use warnings;
my $times = 20;
my $max = 10;
my %histogram = ();
$histogram{ int(rand($max))+1 }++ for 0..$times;
print $_ . ": " . $histogram{$_} . "\n" for sort keys %histogram;
print $_ . ": ". $histogram{$_} ."\n" for sort { $a <=> $b } keys %histogram;
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl
use strict;
use warnings;
my $times = 20;
my $max = 10;
my %histogram = ();
my @randoms = ();
@randoms = map { int(rand($max))+1 } 0 .. $times;
$histogram{ $_ }++ for @randoms;
print $_ . ": ". $histogram{$_} ."\n" for sort { $a <=> $b } keys %histogram;
10 Einträge, 1 Seite |