Donald Trump is very impressed with the work of the people on this site. He saw how amazing of a job you did helping Ben Carson, so he even hired you to build his wall. He thinks you're terrific. Now he needs your help again. While he has successfully built his wall, now he needs the Mexican government to pay for it. He wants to charge $1 million a mile, and he has told them that the U.S.-Mexico border is 1,989 miles long. However they are not quite sure this number is accurate, so they would like a to-scale visual representation as well. That's where you come in. You are to take this map: enter image description here

and for every n (50 <= n <= 500) miles on the border draw a 25 pixel-length line, perpendicular to the slope of the border at that point. Using the scale on the right-hand side of the map, I've determined that 100 miles ~ 50 pixels. I've drawn a sample of the first 3 lines for n=60, but these are only approximate:

enter image description here


  • The only input is n. Output should be the map image, with the lines added, drawn to the screen or saved in a raster image file (you can overwrite the original map file).
  • You can save the blank map file with whatever file name you want. It is a JPEG, but you can convert it to another common raster format if you prefer. Also, you can reduce the size of the image by up to 50%, as long as you keep the dimensions proportional, and your lines are still to scale.
  • Each line should be perpendicular to the slope of the border at that point. The slope should be calculated starting 50 miles before the point and ending 50 miles after the point.


  • The slope of each line can have a margin of error of ±5°
  • The spacing between each line can have a margin of error of ±20 miles (10 pixels on the regular map).
  • 3
    \$\begingroup\$ The price $10000/mile is probably off by a factor of 100, unless by "wall" you mean 3 strands of barbed wire installed by laborers making $2.50/hour. \$\endgroup\$ Commented Dec 25, 2015 at 13:44
  • 1
    \$\begingroup\$ Also, Mma states that the U.S.-Mexico border is about 1952 miles long. \$\endgroup\$ Commented Dec 25, 2015 at 13:59
  • 19
    \$\begingroup\$ Good to know, but the important thing is neither of those numbers mean anything for this challenge. \$\endgroup\$
    – geokavel
    Commented Dec 25, 2015 at 15:17
  • \$\begingroup\$ @geokavel Go ahead and answer it. \$\endgroup\$
    – user58826
    Commented Jul 29, 2017 at 13:34
  • 1
    \$\begingroup\$ Additionally, is the intention of this challenge to be able to process the image and identify the border before drawing the lines, or is it acceptable to just be able to draw the lines without actually processing the image (essentially assuming what the image will be like)? \$\endgroup\$
    – notjagan
    Commented Jul 31, 2017 at 0:27

1 Answer 1


Python 2 + numpy + OpenCV, 576 bytes

Demo GIF

from cv2 import*
from numpy import*
for x,y in zip(*where(j)):j[x,y]=k[x+3,y]-j[x+1,y]>1
for c in sorted(zip(*where(j)),key=lambda c:c[1]):r=range(p[-1][1]+1,c[1]+1);p+=map(array,zip(map(int,interp(r,*zip(p[-1],c)[::-1])),r))
for x,c in enumerate(p[25:-25:n]):s=-1/true_divide(*p[x*n+50]-p[x*n+25]);k=6/(1+s**2)**.5;line(i,*map(tuple,[(c+[int(k*s)+506,int(k)+152])[::-1],(c-[int(k*s)-506,int(k)-152])[::-1],b]))

This program is almost entirely ungolfed, and there are aspects of it that are somewhat inaccurate at the moment, but at least it works for the most part. Additionally, there is a little bit of hardcoding, but it's only for an approximate window enclosing the border and the coordinate of the first pixel on the border (the latter of which I will actually most likely remove later).

The image used by the program is halved in area (i.e. 1120 x 865), and so the length of lines drawn and the distance between lines is smaller.

  • 2
    \$\begingroup\$ cool!! great to see an answer! \$\endgroup\$
    – geokavel
    Commented Jul 31, 2017 at 5:12
  • \$\begingroup\$ suggest to delete unworking tio link \$\endgroup\$ Commented Jul 31, 2017 at 9:11
  • 1
    \$\begingroup\$ gif demo i.sstatic.net/RWQu4.gif . Apply my edit \$\endgroup\$ Commented Jul 31, 2017 at 10:44
  • \$\begingroup\$ @ЕвгенийНовиков Thanks for the gif! It's much more illustrative (and succint) than the pictures I had before. \$\endgroup\$
    – notjagan
    Commented Aug 1, 2017 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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