David (dblume) wrote,
David
dblume

Fifth Grade Homework - Nine digit pandigital prime number

Yesterday my daughter in the fifth grade got the following homework assignment "arrange the digits one through nine into a nine-digit prime number." (Note, since zero wasn't included, it's not really a pandigital number.)

So I asked her how she'd start. She started the way I'd want her to, by excluding the digits 2, 4, 5, 6, and 8 from the units place. And then...

...we got nuthin'.

What did the teacher want? Could we use the computer to test answers? Did the teacher teach some tricks I don't know about? Maybe.

After trying and failing to construct a few nine-digit nearly pandigital prime numbers, I finally gave into every programmer's temptation.

The brute-force tactic! Test them all! In Python, it looks like this:

#!usr/bin/python
import itertools

l = '123456789'
for p in itertools.permutations( l ):
    n = int( ''.join(p) )
    if isprime( n ): # find an implementation on the web
        print "Found it!", n
        break
 

We ran it and... What the hey‽ There isn't any such prime‽ What kind of stunt is this teacher trying to pull?
Tags: code, geek, programming, python, solved
Subscribe

  • My feed URL has changed

    If anyone here follows my personal blog with a feed reader, you'll have to change the feed URL manually. The old URL can't redirect to the new one.…

  • Progress on my Google+ and LJ backups

    Since Google is going to shut down Google+, I decided it was time to really make a home for my LiveJournal backup and my Google+ backup. Working…

  • In Case of Link-Rot

    If anything should happen to this journal, a backup of it should eventually appear at this location. I don't expect or plan for anything to happen…

  • Post a new comment

    Error

    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 4 comments