5
\$\begingroup\$

You want to write your English essay. However, all characters on your keyboard broke other than the arrow keys and the enter key. You want to find out how to place the characters so you can write your essay with the least movement.

Formally, you have to assign to each character of !"$%&'()+,-./0123456789:;<=?[]`abcdefghijklmnopqrstuvwxyz⇦⇧ a unique 2D integer coordinate, and minimize \$ d = \sum_{c_1 , c_2} {\text{freq}(c_1, c_2) \text{dist}(c_1, c_2)} \$, with \$\text{dist}\$ being the Manhattan destince between the position of the characters, and \$\text{freq}\$ being the frequency of the character pair, which is described here, with the frequency of each pair not detailed assumed \$0\$. Note that some pairs appear in both permutations - you have to take into account both of them.

Scoring

The winner is the code which would produce the best result in a minute on my computer (Intel Core i7-9700 with 8 threads, 32GB RAM), with the tie breaker being the time until that result is found.

Rules

  • Your language must have a freely available interpreter/compiler capable of running on Linux
  • Standard loopholes are disallowed, except optimizing for the given test cases - you are allowed (and even expected) to fine-tune your solution to produce the best solution on this given test case.
  • You can't hardcode calculations - the solution should be found by the code during its execution, not beforehand.
  • You can use any reasonable output format (i.e. output your solution and when did you find it when your program terminates, output your solution whenever the program improves it, etc.).
  • You will receive the frequency JSON in stdin.
  • Your solution must be deterministic. You can use PRNGs, you just have to hardcode their seed.
\$\endgroup\$
7
  • \$\begingroup\$ Just out of curiosity: I guess the top arrow stands for 'shift'? But I'm not sure about the left arrow. \$\endgroup\$
    – Arnauld
    Commented Jul 2, 2022 at 15:46
  • 2
    \$\begingroup\$ The top arrow is shift, and the left arrow is backspace. I calculated the frequencies from OANC, assuming you delete 10% of characters you write \$\endgroup\$ Commented Jul 2, 2022 at 15:48
  • \$\begingroup\$ is compile time included in the one minute? \$\endgroup\$
    – MarcMush
    Commented Jul 2, 2022 at 15:50
  • \$\begingroup\$ @MarcMush no, but you have to do you calculations in the one minute - you can't just calculate a solution in C++ templates, for example \$\endgroup\$ Commented Jul 2, 2022 at 15:51
  • 2
    \$\begingroup\$ Related but with only one dimension and different rules. \$\endgroup\$
    – Arnauld
    Commented Jul 2, 2022 at 17:59

0

Your Answer

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