Finding a prime number whose binary representation is a giraffe (or a T-Rex)

Odd Number Theorists

First, here is a prime number whose binary representation is a T-Rex.

Math with bad drawings asked for a prime number whose binary representation is a giraffe. This lead to discussion on Math.reddit and Hacker news which led to finding such a prime number.

342581792649127676198127791406119644054852809184750511204770992210601825938383173228625368612512343524580568135765381129832784929140287102447656231670490278371618738040053550924844754083137995849927287014555199009052294292243605111352278964229602623894816760629354416193979550552423279842373621548435137856781153105076831681645952473068169294190544029391463758663828828100567003458546392021905815042131115480711892076216081858013250696070743624005842779807059777397154653840706692288630135185563366228931093496037459868457738024280865863648682544327375771172685872176976999577303715645442779935499071380556380855234358517399907184246818275843840363379983214925406281243183361618849192180391506653641933784053451121171160334712857092937535606122822893204604775038632348974223351004456787673186165100098223897371450275291114458983950607846718107603195397991880820766444935587675531082421404505700110617860358142315360174185418283092141238404865012380329781867103175076882601367389664213176688432343205501275425887396821357210158983064167712232404771958406106398750988506833703615072967113838953

You can see the binary representation on reddit.

As Nathaniel Borenstein said It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter.

So the obvious next step is to generalize this is to program which can take an image and find a primary number whose binary representation is the image.

We run this for an Argentinosaurus image

python prime_dinosaur.py -f ~/Downloads/argentinosaurus.jpg -s 40

Which gives us

How does this work?

  • We read the image and convert to desired size
  • The image data is converted to monochrome and pixels darker (lower) than a threshold are converted 1, rest pixels are zero.
  • This data is read in in a numpy array
  • This 2d array is flattened, and treated as a bitarray to get a number
  • We then start incrementing the number until we get a prime.
  • The primality is tested using the Miller Rabin test.
  • When such a number is found the number is converted to its binary representation, and displayed in a square grid.

The full code is:

Thank you for reading the Agiliq blog. This article was written by shabda on Jan 21, 2018 in pythonfun .

You can subscribe ⚛ to our blog.

We love building amazing apps for web and mobile for our clients. If you are looking for development help, contact us today ✉.

Would you like to download 10+ free Django and Python books? Get them here