Brain Teasers
A Prime Example
Can you think of three different two-digit prime numbers in which:
(i) the average of ANY TWO of the numbers is a prime, and
(ii) the average of all three of the numbers is a prime?
(i) the average of ANY TWO of the numbers is a prime, and
(ii) the average of all three of the numbers is a prime?
Hint
The average of two of the numbers is 59.Answer
The numbers are 11, 47, and 71.The average of 11 and 47 is 29,
the average of 11 and 71 is 41,
the average of 47 and 71 is 59,
and the average of all three numbers is 43 .
Hide Hint Show Hint Hide Answer Show Answer
What Next?
View a Similar Brain Teaser...
If you become a registered user you can vote on this brain teaser, keep track of which ones you have seen, and even make your own.
Solve a Puzzle
Comments
That's a nugget. Very good!
Great puzzle but way too hard for me. Is there a systematic way of arriving at these?
A systematic way to solve it (about 30 minutes): write down all primes between 10 and 100 (there are 21 of them). Now check all pairs to get the prime averages (there are 27 pairs like 11-23, 11-47, 11-71, 11-83, 13-61, 13-73). Now you need the third number. This number has to build a pair with one number of another pair. For example: 11-23 is a pair and 23-59 is a pair too. So you get 11-23-59, or 19-67 is a pair and 67-79 too: you get 19-67-79. There are 17 sets of 3 numbers. Now check the average of all 3 to be a prime. You get 6 sets, and when you check all pair combinations in each set, there is only one combination (11-47-71) that holds the solution. I hope I could explain it in an understandable way. I wish you a nice day-Gerd
I have a different answer. The answer to the question asked is 'no'!!!
was i supposed to figure that out?
good teaser
VERY hard
good teaser
VERY hard
Brute force approach...
#!/usr/bin/perl
use strict;
# Return true if arg is prime, otherwise false.
sub isPrime {
my $i = shift;
for (my $j=2; $j arg.
sub nextPrime {
my $p = shift;
do { $p++ } until isPrime($p) && return $p;
}
# Command-line arguments, use default if not supplied.
my $min = @ARGV > 0 ? @ARGV[0] : 10;
my $max = @ARGV > 1 ? @ARGV[1] : 100;
# Main program loop.
for (my $p1=nextPrime($min); $p1
#!/usr/bin/perl
use strict;
# Return true if arg is prime, otherwise false.
sub isPrime {
my $i = shift;
for (my $j=2; $j arg.
sub nextPrime {
my $p = shift;
do { $p++ } until isPrime($p) && return $p;
}
# Command-line arguments, use default if not supplied.
my $min = @ARGV > 0 ? @ARGV[0] : 10;
my $max = @ARGV > 1 ? @ARGV[1] : 100;
# Main program loop.
for (my $p1=nextPrime($min); $p1
Ugh, beaten by HTML suppression again... This should really have a preview option...
TAKE 2
#!/usr/bin/perl
use strict;
# Return true if arg is prime, otherwise false.
sub isPrime {
my $i = shift;
for (my $j=2; $i/2>=$j || return 1; $j++) {
return 0 if (int($i/$j) == $i/$j);
}
}
# Return next prime > arg.
sub nextPrime {
my $p = shift;
do { $p++ } until isPrime($p) && return $p;
}
# Command-line arguments, use default if not supplied.
my $min = @ARGV > 0 ? @ARGV[0] : 10;
my $max = @ARGV > 1 ? @ARGV[1] : 100;
# Main program loop.
for (my $p1=nextPrime($min); $max>=$p1; $p1=nextPrime($p1)) {
for (my $p2=nextPrime($p1); $max>=$p2; $p2=nextPrime($p2)) {
for (my $p3=nextPrime($p2); $max>=$p3; $p3=nextPrime($p3)) {
# Test each set of 3 primes.
if (isPrime(($p1+$p2)/2) &&
isPrime(($p2+$p3)/2) &&
isPrime(($p1+$p3)/2) &&
isPrime(($p1+$p2+$p3)/3)) {
# We found an answer!
print "$p1, $p2, $p3\n";
}
}
}
}
print "Complete.\n";
exit(0);
TAKE 2
#!/usr/bin/perl
use strict;
# Return true if arg is prime, otherwise false.
sub isPrime {
my $i = shift;
for (my $j=2; $i/2>=$j || return 1; $j++) {
return 0 if (int($i/$j) == $i/$j);
}
}
# Return next prime > arg.
sub nextPrime {
my $p = shift;
do { $p++ } until isPrime($p) && return $p;
}
# Command-line arguments, use default if not supplied.
my $min = @ARGV > 0 ? @ARGV[0] : 10;
my $max = @ARGV > 1 ? @ARGV[1] : 100;
# Main program loop.
for (my $p1=nextPrime($min); $max>=$p1; $p1=nextPrime($p1)) {
for (my $p2=nextPrime($p1); $max>=$p2; $p2=nextPrime($p2)) {
for (my $p3=nextPrime($p2); $max>=$p3; $p3=nextPrime($p3)) {
# Test each set of 3 primes.
if (isPrime(($p1+$p2)/2) &&
isPrime(($p2+$p3)/2) &&
isPrime(($p1+$p3)/2) &&
isPrime(($p1+$p2+$p3)/3)) {
# We found an answer!
print "$p1, $p2, $p3\n";
}
}
}
}
print "Complete.\n";
exit(0);
To post a comment, please create an account and sign in.
Follow Braingle!