trip2mars.pl 780 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/perl
  2. # Author: Trizen
  3. # License: GPLv3
  4. # Date: 15 October 2013
  5. # https://trizenx.blogspot.com
  6. # This program solves the "Trip to Mars" problem
  7. # See: https://www.youtube.com/watch?v=k-zrgRv9tFU
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. my %max = (
  12. hours => 0,
  13. games => 0,
  14. movies => 0,
  15. );
  16. foreach my $x (0 .. 200) {
  17. foreach my $y (0 .. 200 - $x) {
  18. next if 8 * $x + 3 * $y > 1200;
  19. next if 0.2 * $x + 0.8 * $y > 130;
  20. my $hours = 4 * $x + 2 * $y;
  21. if ($hours > $max{hours}) {
  22. $max{hours} = $hours;
  23. $max{games} = $x;
  24. $max{movies} = $y;
  25. }
  26. }
  27. }
  28. say "To maximize the time on breaks, you need to buy $max{games} games and $max{movies} movies.";