#!/usr/bin/perl use strict; use warnings; #USAGE: ./alvin.pl 6 3 my $init_popsize = $ARGV[0] - 1; my $maxtime = $ARGV[1]; my @age; my @gender; my @weight; my @population = ( 0 .. $init_popsize ); for my $i ( 0 .. $#population ) { $age[$i] = int( rand(10) ); #Alter my $r1 = rand(); if ( $r1 <= 0.4 ) { #Geschlecht (0=männlich, 1=weiblich) $gender[$i] = 0; } else { $gender[$i] = 1; } my $r2 = rand(); if ( $r2 <= 0.3 ) { #Gewicht $weight[$i] = 0; } elsif ( $r2 > 0.3 && $r2 <= 0.6 ) { $weight[$i] = 1; } else { $weight[$i] = 2; } printf "$age[$i] $gender[$i] $weight[$i]\n"; } printf "\n"; Aussen: for my $t ( 1 .. $maxtime ) { Innen: for my $i ( 0 .. $#population ) { $age[$i]++; if ( $age[$i] >= 10 ) { splice( @age, $i, 1 ); splice( @weight, $i, 1 ); splice( @gender, $i, 1 ); splice( @population, $i, 1 ); # $age[$i]++; next Innen; } } for my $i ( 0 .. $#population ) { printf "$age[$i] $gender[$i] $weight[$i]\n"; } my $population = $#population + 1; printf "\npopulation: $population\n"; }