49
5
Tupper's Self-Referential Formula (copied from Wikipedia)
Tupper's self-referential formula is a formula defined by Jeff Tupper that, when graphed in two dimensions at a very specific location in the plane, can be "programmed" to visually reproduce the formula itself. It is used in various math and computer science courses as an exercise in graphing formulae.
Where is the floor function.
Let k
be the following 543-digit number:
960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719
If one graphs the set of points (x, y)
in 0 <= x < 106
and k <= y < k + 17
satisfying the inequality given above, the resulting graph looks like this (note that the axes in this plot have been reversed, otherwise the picture comes out upside-down):
So what?
The interesting thing about this formula is that it can be used to graph any possible black and white 106x17 image. Now, actually searching through to search would be extremely tedious, so there's a way to figure out the k-value where your image appears. The process is fairly simple:
- Start from the bottom pixel of the first column of your image.
- If the pixel is white, a 0 will be appended to the k-value. If it is black, append a 1.
- Move up the column, repeating step 2.
- Once at the end of the column, move to the next column and start from the bottom, following the same process.
- After each pixel is analyzed, convert this binary string to decimal, and multiply by 17 to get the k-value.
What's my job?
Your job is to create a program which can take in any 106x17 image, and output its corresponding k-value. You can make the following assumptions:
- All images will be exactly 106x17
- All images will only contain black (#000000) or white (#FFFFFF) pixels, nothing in between.
There's a few rules, too:
- Output is simply the k-value. It must be in the proper base, but can be in any format.
- Images must be read from either a PNG or PPM.
- No standard loopholes.
Test Images
[ ] should produce ~1.4946x10542
[ ] should produce ~7.2355x10159
[ ] should produce 21801 * 17
[ ] should produce (21802-1) * 17
Check out this Gist for the exact solutions.
This is code-golf, so least number of bytes wins.
Helpful Links
Can I take in a PPM? – Maltysen – 2015-06-16T20:36:27.193
EDIT: Yes, PPM format is allowed. When I came up with the program I intended for PNGs to be used, but allowing PPM should allow for more golfing languages to participate. – Kade – 2015-06-16T20:46:24.460
3As I was reading this question, before getting to "What's my job" part, I was positive I'm going to see the word
quine
somewhere. – Jacob – 2015-06-17T12:21:12.203I won't pretend to be a programmer who can do this kind of stuff, instead I will simply present an innocent, earnest question: Yes, but can it be done in reverse? I.e. feeding in the solution and seeing the *.png generated as the result? – None – 2015-06-17T21:06:45.293
@NotAsSharpAsYouGuys: if you have arbitrary precision arithmetic it's trivial, you just have to check the result of that formula for each pixel and output the resulting image. – Matteo Italia – 2015-06-18T11:31:48.483