5
\$\begingroup\$

The riddle

In yesterday's newspaper, I found a puzzle in which a Rook should start in the lower-left corner of a 12x12 checkerboard and then, during a round trip, visit each field exactly once except for a selection which must be avoided. The puzzle came with a picture that identified the fields to be avoided as black:

Blank checkerboard

After some minutes, I came up with a solution, that you can find here.
(There's no pic of the solution because you might want to challenge yourself by solving it first...)

The challenge

To write code that produces the same output as my code (that's in TikZ):

\documentclass[tikz,border=1cm]{standalone}\def~{document}\begin~\tikz{\def~{)rectangle++(,)(}\filldraw[step=1]grid(12,12)(8,0~4,~0,3~8,5~11,5~,8~11,9~2,10~4,11~7,11~,);\def~#1#2#3{)-|++(6-#1,4-#2)-|++(6-#3,4-}\draw[line width=2mm,red](.5,.5~1355~5353~5356~7540~7375~7575~7375~7373~7372~5555~5553~5552~7375~7373~7345~5355~5555~5355~5272~5395~5673~7373~7583~9555~7955~5555~8376);\fill[blue](.5,.5)circle(.3)}\end~

of the picture that shows the solution to the Rook's Round Trip. This is Code Golf!

Requirement(s) for the In-/Output

  • Use whatever language you want.
  • From your output, be able to somehow produce the pixelwise
    exact same PNG as in the code section below.

PNG code

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABXoAAAV6AgMAAAAuWCySAAAADFBMVEX///8AAAD/AAAAAP8xSkYMAAAKsklEQVR4Aezdx5HcRhSA4a2aOz2TYBLDEOg6CUSxSeAuRwclsfHotFdZSBiJLftqt7deA0Po+6+vHlDzVcuCM7g4myRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJksqt04s7+D5fYVCiwo0H0eBp82d/0HvAly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvlNylw2+N9z8ixbfZ1NuX5ynL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fC9Tnh/f3jfYePB3rXbfGKVl8IwvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX75840ptWhpLQvVSCRvDMnhbGmrcaLjUi1XOb/tpbD/xD9pP47bnly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvny7v80tLvaN+2KjDb58+fLly5cvX758+fLly5cvX758+fLly5cvX758+W7rG8M3+7bfI//ZbryR8sSZL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fMvNnXzHcmYN02+9Tdi4/aVerHJ+442dnN+nfPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5Zv//reWjfZL5b+0jS9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvvv0DT57341gkP+YmC9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnyzfUttWhpLQ4kb4WBYBm9LXLiRMOh5fkvU7s9vfA++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPnyTfHNf2Nc6Bv2xRobfPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny3YFv1g+r1hIeEwcb6ffgy5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cv31I7oYwlo8RLhQ3LPd6ueo8XDa7Jh8755cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL99gEJa0sf1r3vjy5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5bsD34ZB1j3aP2K8kTqo8eXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLl2+pTUtjqbUMghIuNSyDtyUu3kgfvNjs/Dq/fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5bvpi+G2e81b0C58+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLlW0vYqGU8Jq51HfDly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5dvqZ1QxlKLB3HxRnrDco+3Zc1e/I/P79NmlPAeTz8fX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLlG7bGxhcpvje8Rm8Hvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58k3fCAcBY5ZvwqVqfPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5Vtq09JYGsrbiAfDMngbD+JSLuX81kFQ/qX48uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXL99xe8xb7hn2xwcZmvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58t30wXLDk9rGx8S9L8WXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++5eZOWmM8jzc2aVhu/rbHpV5k+jq/CeeXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPu/GG7717ztwJcvX758+fLly5cvX758+fLly5cvX758+fLly5cvX77pP6waD+KP2P7ZEy7Fly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLtyW+fPny5cuXL1++fPk2dEIZMzbiwbAM3jYMgoKNpsGLO/g+v/vA+eXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly/fM3nN22Xn17ztyZcvX758+fLly5cvX758+fLly5cvX758+fLly5cvX74xymWfB8tBDxoGjShJvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uVbaieUsdTiQVz7Rn7DcvO3d9+IBy/O9PyWqP2fX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fJtq913Wuc1b0G78OXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLl2+tfdDse5n/bLfbBl++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPmW2rQ0lk2Kbz4sg7fxIC5/40X/85s/SDq/TyOjF/nnly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLdx++387z/EM3X77z0lUnRr7351OdGPnOv3fdhZHv/fmPujDyPX7yverAyPcwf+q6AyPf+9X3pw6MfI9zrQMj3/nPrvim+x7+4nvNN933/l98f+rqy3fmm+57/KvvFd9s33k9X77XfJN9Dyv68v2Jb7Lvfb58d+M7T9sU+4a1+7aX4Hvky3c/vt/x/RRfvnxnvnz58uXLly9fvnz5rpv/fuPLly/fqcbX8yG+fDd7fhz0oHkQ++bd47P48yV8r/km+16s6Mv3im+273E9X76pWnz7f7+F76GrL9+Lvt9/43vs+v1Nvve7fv+Y76Hr9+f5XvT9/Qe+x66/D8P3UP/20IGRbz3AV30Y+R7q8eWb7lv/Fa2DFt8K/FO+Ft8gvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvrv0Lbp1v7YHBwQAABAAgEz0f40ZoMqAKQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAO+uutlkASEAAAAASUVORK5CYII=   

Bonus imaginary internet points

  • Write the code in TikZ
  • Your TikZ-code should compile without any errors, warnings, and boxes.
  • You should be able to produce a PNG-file with Overleaf that, when saved in the same dimensions, must be able to withstand a bitwise comparsion with my solution.
\$\endgroup\$
25
  • 2
    \$\begingroup\$ What are the exact requirements for output? \$\endgroup\$ Jun 1 '20 at 10:07
  • 4
    \$\begingroup\$ Requiring the output to be exactly the same as the image seems unnecessarily restrictive to me. What if there's another solution to this puzzle? Also, please consider allowing other languages to compete, I don't think many of us golf in TikZ. \$\endgroup\$ Jun 1 '20 at 14:06
  • 4
    \$\begingroup\$ After solving this, it seems like this puzzle has a unique solution. Great puzzle I must say. \$\endgroup\$ Jun 1 '20 at 15:11
  • 7
    \$\begingroup\$ To reiterate the second part of @SurculoseSputum comment: would sure be a lot more fun for everybody if we could just solve this puzzle as a straight-up code-golf challenge. Maybe add a Bonus imaginary internet points section for TikZ solutions that are shorter than yours. You could also post your answer as part of the competition! :-) \$\endgroup\$
    – Noodle9
    Jun 1 '20 at 16:27
  • 3
    \$\begingroup\$ Feedback on the question: this is all framed as the rook-solving problem, but ultimately, the goal is simply to generate a particular PNG string? IMHO it doesn't leave a lot of scope for creativity. Would be more interesting if the output just had to "closely resemble" the picture, without requiring pixel perfection or a particular image format. \$\endgroup\$ Jun 7 '20 at 11:11
4
+50
\$\begingroup\$

C (gcc), 959 947 937 bytes

-12 -10 bytes thanks to ceilingcat!

#define Z g&&S(r,c+40,20,q,1)
#define W write(o
H=1402;y=4206;char*s="VDRMOSMWK[I^HaGcFeEgDiCkBlAnAo@p@q?r?s>t>u>u=v=w=w=w<x<x<x<x<x<x<x<x<x=w=w=w=v=v>u>t>t?s?r@q@pAoBmBlCjDhEfFdGbI_J]LYNUPPSJ",*I,d[]="\0o\20\x90\xef",*G=",&&* ,* ,&&*%* %&#%*%*,#,#,&*,*%*)) ) %*%#%*%#%*),*%*,*%*,*)))%*%#%*%#%#)%*%*,*) ,* %*%*%#%#,#%* %*%*,*,#,*),*%*%#%#,#)))%&# ,*,#,#)%&&&&#%# %&#";P[]={0,255,~0<<16,~0},o,C,u,v,i,j,r,c,q=60,z=100;S(a,b,w,h,X){for(h+=a;h/a;h--)for(C=b+w;C/b;)bcopy(P+X,I+h*y+C--*3,3);}main(g){I=memset(malloc(y*H),~0,y*H);for(W=open("a.png",33537),"\x89PNG\r\n\32\n\0\0\0\rIHDR\0\0\5z\0\0\5z\b\2\0\0\0\xDCTSV\0Z\eNIDAT\b\35",43);++i<13;)for(j=0;j<12;8&Z)g=*G++%32,u=j++==5,v=i==7,S(r=i*z+i/7,c=j*z|j>6,z+u,z+v,0),g&&S(r+!v,c+1,98+u,98+v,3),1&Z,r+=40,g&2&&S(r,c,q,20,1),g&4&&S(r,c+40,q,20,1);for(r=61;r--;)S(1281-r,s[r*2]+q,s[r-~r]-q,0,2);for(r=H;r--;I+=W,I,y))*d=!r,W,d,6);W,"\xfc\xa3\xea\xe1\xe8\x93\274a\0\0\0\0IEND\256B`\x82",20);}

Try it online!

Each position on the board is stored in the lower four nibbles of the characters of the string G. A zero means a black tile, otherwise each bit corresponds to one "arm" of a junction:

 0
1 2
 3

So a ┌ junction would be stored as the bits 1100, for example.

We simply loop through the string and draw tiles accordingly. Care is taken to match the jankiness that occurs in the middle of the board (slightly wider tiles and therefore everything shifted down/right thenceforth).

Everything is drawn as filled rectangles. An empty tile is just a black rectangle with slightly smaller white rectangle painted over it.

The circle caused some headache; just the data for it takes almost as much as the data for the rest of the board. I tried some circle-drawing methods, but the circle is not symmetrical, so no luck.

Various CRCs and similar are hardcoded, since we will always output the same image.

Stores output to "a.png".

\$\endgroup\$
5
  • \$\begingroup\$ @ceilingcat Hm, getting "a.png CRC error in chunk IDAT (computed 64aecef3, expected 00004945)" with that. Something to do with the wide-char, it looks like. \$\endgroup\$
    – gastropner
    Jun 10 '20 at 20:20
  • \$\begingroup\$ If you're using gcc on windows, try -fno-short-wchar and see if the wchar_t* literal works \$\endgroup\$
    – ceilingcat
    Jun 10 '20 at 20:49
  • \$\begingroup\$ 929 bytes \$\endgroup\$
    – ceilingcat
    Jun 10 '20 at 21:08
  • \$\begingroup\$ If the wchar_t* literal doesn't work, try this one "\xfc\xa3\xea\xe1\xe8\x93\274a\0\0\0\0IEND\256B`\x82" \$\endgroup\$
    – ceilingcat
    Jun 10 '20 at 21:10
  • \$\begingroup\$ @ceilingcat No such luck on the wide-chars, but well on the second string. \$\endgroup\$
    – gastropner
    Jun 11 '20 at 20:11
2
\$\begingroup\$

Mathematica, 1900 bytes

"H4sIAAAAAAAACsVWa1ATVxSOtRQNYFqIIkrEgiAUQrQODW0Eq6AFKYICrRQlWKjtqCQgYFA24KPBYcCgqGQwBca3xRaoHQwQWEQwMQOIj9ZYNFlDCA8xWZIAIYQk3bR11D/rdPujO3P3nr3nce+53zlnT1Hsps+c8IvwOBzOKTIifAsOZ3fANt6ajawEbg0oQybH2M/j1yOzFWd7Ic850uJQhJybEZGYhcM5uNjGLNyZHxYiRHtk+Nr43D617JdMZTDxnZR9NyImtnr7ai8G3krYNpd391BUPS1jwIe4/fmnzV6GALVEFFg157jzhHmEbz8HSlkhLD599/nFry2MhWMqf8Comw8CRjwdvMmj0BVdvLoxVdeXUy8WAQ7Fxvln8YX434svxF+xYeO8tGHjvLRh47xiw8ZxHktfRlO7gSwXYplH8B/a8g9aCqWWj9YeQhQQKVUX798SVE0ePbj0PYhOmHhXy6a0cO3R1ZIvwaknTMpVbI+2RIlpP+jm68ZhYdwbIaJNS9Yo6jtz4jy1Z8tIV8H6Isf58G1STWWaVcRKBcRtxx4dk+aHjmGzruoybGRfzu0hp3JPehfKd/LPHUHX0U8PytU7p0RDV1gC/r2V06IK7Bc78ngm9Ajc3FT/03RMg9/9E7R4msRCboymZFlBjLeFEMxuqiH9+hPu4TDvzf0kdPHtJczhM40p4sgdfdWRmHekQFlAqazDWRq91I5WxkmgPwofjNjX6RBkYO4tvwVDJR9PYXZHcJDZ/q28DIxb7ej67CmqCtxgFNUVnSQ1URvsKGyHO+2Y3eGPhzQ7+Y5eCsfPO91dU526asQ9XWJeDGVPYgYbMObHXdF1JzHEYbvUcdno4WroA8I497JKmnzyCbtb9ZiBgd3AnvcRXHqknQ6SzqNfTXCi07hp4uF1u62feGDGJC8ETFhSyFdUCGLt0YXreqih8de89i92b/PhEoKab/wHRNLnucU+7JEuQxyh9SdOZO054/dAPmZhO51fNpSLPXTpoFSZpHJrfcI96gk29Q5r0YE5wL48HOyXNuOorgC/KezHnjFmy6OQgEzZ21vqvRK3IrhcON49fJax3yoqyMzpjsVcLVV5ib0t3mwloSNB84ZsaQF/TQ4Ykv/GbfKppRIxxzXzvsDIfufnHJeIlvMpX5gH+IvCGrzZaqjZhB0SqpI22pFB+LEh5h56EkP+OnJu9MxuSHzbWSnt1J7FXmgM7lCJo++oJ0lys4ayx5OT1h9WSexbBcAbiM+xJ70OAfmhrX5lhehF6K5ETbJLiPjkgOUUtpLjF1iOOQS6WG3MV5IFv/P3GNDvfuaW7yjZVh/XQQA9LtBCxmlK5KJrrX5WIfiQ0PGGTFnHRioxZxskXsQSvqneodnxYZcWk8obGYORe3W2PwteUqKxeSLnLC+FIempzcIZPUpzY1gNrWmuNRUzg6DaXgdoI+hxhCkWlMEEuaaCOR+yXoczZ+vJz4TmcbYiqZ1lkOQFL50qHw9xJ8hcIDx4VKnIwOnJI3kD5tUHjQvGZeYBU7egERbHgDHA1el9QLGJIaTYr4AOgyRoBKg2LpiUaSvvGoqYOyACCLgqH8t6T11gis6nN4Fa4phMpxK6Q2v+OtgDgfK18xYUIN91BdbWXXRDGMBT0sTmTB2eKjiuoB3g+lus3gLb1vVwFfw9SAGiTAzjpiHhUFIfaxIWBDxhiQU1cL4GbiPLWDS9gcrTmFbqDaU8jZBvNOmjDLLeGROh2CC7YzKtQKZKdwLQNZ3PeOoK5gAsKwQCDibLlFdfFZMMFRyqngRGjcmxaD0jIrfh2oMqhb/d/9Dkvr7laSZgnbVnKNulsP9gkK3bj1y/Kbx2XcrhPwH+UUsXJwwAAA=="~ImportString~"Base64"

I tried to use the grid-board to my advantage, and it still probably would be, but the thicknesses of the lines seem to very by 1 px either way, making this a likely comparable solution in length.

\$\endgroup\$
2
\$\begingroup\$

Python 2, 3864 3846 3832 3815 bytes

I’m new, so I could use help shortening it. It outputs to a file in the same folder called i.png.

from base64 import* open('i','wb').write(b64decode("iVBORw0KGgoAAAANSUhEUgAABXoAAAV6AgMAAAAuWCySAAAADFBMVEX///8AAAD/AAAAAP8xSkYMAAAKsklEQVR4Aezdx5HcRhSA4a2aOz2TYBLDEOg6CUSxSeAuRwclsfHotFdZSBiJLftqt7deA0Po+6+vHlDzVcuCM7g4myRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJkiRJksqt04s7+D5fYVCiwo0H0eBp82d/0HvAly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvlNylw2+N9z8ixbfZ1NuX5ynL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fC9Tnh/f3jfYePB3rXbfGKVl8IwvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX75840ptWhpLQvVSCRvDMnhbGmrcaLjUi1XOb/tpbD/xD9pP47bnly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvny7v80tLvaN+2KjDb58+fLly5cvX758+fLly5cvX758+fLly5cvX758+W7rG8M3+7bfI//ZbryR8sSZL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fMvNnXzHcmYN02+9Tdi4/aVerHJ+442dnN+nfPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5Zv//reWjfZL5b+0jS9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvvv0DT57341gkP+YmC9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnyzfUttWhpLQ4kb4WBYBm9LXLiRMOh5fkvU7s9vfA++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPnyTfHNf2Nc6Bv2xRobfPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny3YFv1g+r1hIeEwcb6ffgy5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cv31I7oYwlo8RLhQ3LPd6ueo8XDa7Jh8755cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL99gEJa0sf1r3vjy5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5bsD34ZB1j3aP2K8kTqo8eXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLl2+pTUtjqbUMghIuNSyDtyUu3kgfvNjs/Dq/fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5bvpi+G2e81b0C58+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLlW0vYqGU8Jq51HfDly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5dvqZ1QxlKLB3HxRnrDco+3Zc1e/I/P79NmlPAeTz8fX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLlG7bGxhcpvje8Rm8Hvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58k3fCAcBY5ZvwqVqfPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5Vtq09JYGsrbiAfDMngbD+JSLuX81kFQ/qX48uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXL99xe8xb7hn2xwcZmvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58t30wXLDk9rGx8S9L8WXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++5eZOWmM8jzc2aVhu/rbHpV5k+jq/CeeXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPu/GG7717ztwJcvX758+fLly5cvX758+fLly5cvX758+fLly5cvX77pP6waD+KP2P7ZEy7Fly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLtyW+fPny5cuXL1++fPk2dEIZMzbiwbAM3jYMgoKNpsGLO/g+v/vA+eXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly/fM3nN22Xn17ztyZcvX758+fLly5cvX758+fLly5cvX758+fLly5cvX74xymWfB8tBDxoGjShJvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uVbaieUsdTiQVz7Rn7DcvO3d9+IBy/O9PyWqP2fX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fLly5cvX758+fJtq913Wuc1b0G78OXLly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLl2+tfdDse5n/bLfbBl++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPny5cuXL1++fPmW2rQ0lk2Kbz4sg7fxIC5/40X/85s/SDq/TyOjF/nnly9fvnz58uXLly9fvnz58uXLly9fvnz58uXLdx++387z/EM3X77z0lUnRr7351OdGPnOv3fdhZHv/fmPujDyPX7yverAyPcwf+q6AyPf+9X3pw6MfI9zrQMj3/nPrvim+x7+4nvNN933/l98f+rqy3fmm+57/KvvFd9s33k9X77XfJN9Dyv68v2Jb7Lvfb58d+M7T9sU+4a1+7aX4Hvky3c/vt/x/RRfvnxnvnz58uXLly9fvnz5rpv/fuPLly/fqcbX8yG+fDd7fhz0oHkQ++bd47P48yV8r/km+16s6Mv3im+273E9X76pWnz7f7+F76GrL9+Lvt9/43vs+v1Nvve7fv+Y76Hr9+f5XvT9/Qe+x66/D8P3UP/20IGRbz3AV30Y+R7q8eWb7lv/Fa2DFt8K/FO+Ft8gvnz58uXLly9fvnz58uXLly9fvnz58uXLly9fvrv0Lbp1v7YHBwQAABAAgEz0f40ZoMqAKQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAO+uutlkASEAAAAASUVORK5CYII="))

I could use advice on shortening it. This is the first time I have ever done anything like this.

\$\endgroup\$
6
  • \$\begingroup\$ Would it be shorter to store the PNG in a bytestring directly, escaping all offending characters? (there's also base64.b85encode and base64.b8decode; these seem to be better than base64) Besides, you can remove c.close(), and the with statement seems unnecessary because the program will shortly exit and close everything anyway. You can also skip the definitions of b and a and simply use c.write(a2b_base64("long_string")). \$\endgroup\$ Jun 7 '20 at 4:30
  • \$\begingroup\$ I removed c.close() and defining b and a, but on my editor it wouldn’t run without the with statement. I don’t know how to use the base64.decode(), but I can look it up. Thank you for the help! \$\endgroup\$ Jun 7 '20 at 4:52
  • \$\begingroup\$ You can rearrange everything a bit to cut it down to 3815 bytes. \$\endgroup\$ Jun 8 '20 at 7:02
  • \$\begingroup\$ Thanks for the suggestion on cutting it! I didn’t change the import statement but I did cut the with statement. It didn’t produce a png when written to a file without an extension, or it could have been 4 bytes shorter. \$\endgroup\$ Jun 8 '20 at 13:52
  • \$\begingroup\$ @BardicWizard file name should be irrelevant, as the format is still PNG. You can check that by opening the file in any PNG viewer (or even web browser like Google Chrome). Also I'm not sure why you don't want to change the import statement, as it saves 1 byte. \$\endgroup\$ Jun 8 '20 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.