Skip to main content
4 of 5
deleted 1596 characters in body
Calvin's Hobbies
  • 90k
  • 46
  • 339
  • 555

Optimize paper folding to mitigate inkblots

Dark black ink has splattered all over your white sheet of printer paper! The obvious solution is to fold the paper so black and white parts meet and both become grey as the ink diffuses. Then unfold and refold until your paper is all equally grey.

Finding the best way to make these folds is your task in this coding challenge. This Pastebin contains four different sized grids of ones and zeros. Each grid represents a piece of ink splattered paper that you must turn grey. Zeros are paper and ones are ink.

In these grids, only horizontal and vertical folds along the spaces between lines and columns are valid. When a fold is made the pairs of overlapping values are averaged. Folds are done one at a time and always unfolded. Folds only change the ink distribution, not the size of the paper.

Rn denotes folding the left edge of the grid to the right, starting after the nth column. Dn denotes folding the top edge of the grid downward fold, starting after the nth row. (n is 1-indexed)

Example

Given this grid

0 1 1 1
0 0 0 0
0 0 0 0

a D1 fold means "fold the entire top row down then unfold".

0 0.5 0.5 0.5
0 0.5 0.5 0.5
0   0   0   0

Then an R2 will produce

0.25 0.5 0.5 0.25
0.25 0.5 0.5 0.25
   0   0   0    0

and another R2 will not change anything.

Goal

Your goal is to write an algorithm that finds the best ink-spreading folding sequence for each of the four grids using exactly 8 folds each time. The folds may be any combination of Rs or Ds.

Scoring

The score of your submission is the sum of your scores for each grid. A grid's score is the sum of the absolute differences between each of its values and its average (its sum divided by its area). Lower scores are better. A score of 0 is perfect, but is probably impossible in only 8 folds.

You must report your four 8-step folding sequences with your code in your answer. This is so we can verify your algorithm really works.

Please put them in this form:

20*20R1D2R3D4R5D6R7D8
40*20R1D2R3D4R5D6R7D8
40*40R1D2R3D4R5D6R7D8
20*80R1D2R3D4R5D6R7D8

(I will soon write a script that calculates a score given the four sequences.)

Naturally you should not copy someone else's sequence submission. Sequences for each grid only belong to the person who first created them.

Clarifications

  • Ideally your algorithm will work well on any grid, though you can tailor it to these specific ones.

  • You must submit your code with your sequence. To win you need the smallest-scoring set of 8-step folding sequences that has not already been posted, and also an algorithm that stands up to public scrutiny. Explain your code, don't obfuscate it.

  • The grid should never contain negative numbers.

  • Standard loopholes apply.

Calvin's Hobbies
  • 90k
  • 46
  • 339
  • 555