Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
taller in front
#perl 5.22.1 @H = (2, 6, 4, 5, 1, 3); # Heights @T = (1, 0, 2, 0, 1, 2); # Number of taller people in front my %hash=(); foreach my $person (0..$#H){ $hash{$person}={height=>$H[$person], tallerInFront=>$T[$person], peopleTaller =>[ map{$H[$_]>$H[$person]?$_:()}(0..$#H)], } } my $before=my $after=score(); my @currentOrder=(0..$#H); for (0..100000){ $before=$after; my $a=rand()*@currentOrder;my $b=($a..$#currentOrder)[rand()*(@currentOrder-$a)]; @currentOrder[$a,$b]=@currentOrder[$b,$a]; $after=score(); @currentOrder[$a,$b]=@currentOrder[$b,$a] if $before>=$after; } print score(); sub score{ my $score=0; foreach $person(1..$#currentOrder){ $score++ if $hash{$currentOrder[$person]}{tallerInFront} == scalar map{$hash{$currentOrder[$_]}{height}>$hash{$currentOrder[$person]}{height}?$_:()}(0..$person-1) } return $score }
run
|
edit
|
history
|
help
0
Lol
test hello worl perl
matrx travarsal
array flipper
perl
Perl
Perl
Anchal 101712
taller in front
5_5