Created
August 8, 2012 13:22
-
-
Save perforb/3294987 to your computer and use it in GitHub Desktop.
Ants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature qw(say); | |
use constant LENGTH => 10; | |
my ($n, $min, $max) = (shift @ARGV || 8, 0, 0); | |
my @positions = (); | |
push @positions, int(rand(LENGTH + 1)) for (1 .. $n); | |
for my $position (@positions) { | |
$min = max($min, min($position, LENGTH - $position)); | |
$max = max($max, max($position, LENGTH - $position)); | |
} | |
say '[', join(', ', @positions), ']'; | |
printf("MIN:%d MAX:%d\n", $min, $max); | |
sub max { $_[0] > $_[1] ? $_[0] : $_[1] } | |
sub min { $_[0] < $_[1] ? $_[0] : $_[1] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
LENGTH = 10 | |
positions = (2, 6, 8) | |
t_min, t_max = 0, 0 | |
for pos in positions: | |
t_min = max(t_min, min(pos, LENGTH - pos)) | |
t_max = max(t_max, max(pos, LENGTH - pos)) | |
print "MIN:" + str(t_min) | |
print "MAX:" + str(t_max) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment