title: Largest Compatible Maze

text:
# Question
Title: Largest Compatible Maze
# Background

Consider an \\$n\times n\\$ grid, where each cell is either empty (denoted by `.`) or a wall (denoted by `#`). We say that two cells are *adjacent* if they share an edge (a corner is not enough). A *path* is a sequence of distinct empty cells \\$s\_0,s\_1,\ldots,s\_k\\$ such that cells \\$s\_i\\$ and \\$s\_{i+1}\\$ are adjacent for \\$0\le i\<k\\$.

We say that a grid is a *maze* if the following conditions hold.

1. There is at most one path between any two empty cells.
2. The following two \\$2\times 2\\$ patterns do not occur anywhere in the grid.

```
  #.             .#
  .#             #.

```

A maze is **not** required to be connected (i.e. it is allowed to have two empty cells without any paths between them).

Here are a few examples of mazes.

```
.###                 #...                 ....
.###                 ###.                 #.##
.#..                 ..#.                 #.##
.###                 #...                 ....

```

Here are a few examples of grids which are **not** mazes.

```
....                 ##.#      Do not satisfy rule 1.
#.#.                 #..#
#...                 #..#
##.#                 #.##

```

```
##..                 ##.#      Do not satisfy rule 2.
..#.                 ##.#
#.#.                 .#.#
#...                 #..#

```

# Challenge

Here is a \\$128\times 128\\$ maze. It has \\$991\\$ empty cells and \\$15393\\$ walls. Your task is to tear down as many walls as possible, making sure that the grid you obtain is still a maze.

More formally, let \\$M\\$ be the maze given above. A submission to this challenge consists of a \\$128\times 128\\$ maze \\$M'\\$ such that every empty cell in \\$M\\$ is also empty in \\$M'\\$.

## Scoring

This is : the more walls you manage to tear down, the better.

Your score will be equal to the number of walls (`#`) in the maze you submit. Lower score is better.

## Notes

* The maze \\$M\\$ given above doesn't have any special properties, to the best of my knowledge. It was generated as randomly as possible, fixing the average density of empty cells.
* Here is a python script that checks whether your submission is valid and tells you your score (just paste the maze in the "Input" section)

# Answer
# Score: ~~8066~~ 8065 walls

I found an 8066 wall solution using dynamic programming over solutions that can be recursively decomposed by splitting on a row or column consisting entirely of floors or entirely of walls. The implementation of this apparently simple idea was rather more complicated than its description, since there are 17 different types of subproblems depending on the borders and the connectivity between them.

I then removed one wall by hand-editing seven cells in rows 119–122, columns 60–63.

This is an **optimal** solution. Proof:

Add a one-cell border using \\$516\\$ extra walls. Consider the planar graph whose vertices are the \\$w\\$ centers of walls, and whose edges are the \\$a\\$ wall-wall adjacencies. This graph is connected (because any component of walls not connected to the border would be encircled by a forbidden cycle of floors), and has \\$f \ge 2\\$ faces (at least an inside and outside). By Euler’s formula, \\$w - a + f = 2\\$, so \\$w - a \le 0\\$.

Now consider the different planar graph whose vertices are the \\$131^2\\$ corner points of walls, and whose edges are the \\$4w - a\\$ sides of walls. None of these \\$131^2\\$ vertices are missing (because an isolated one would again be encircled by a forbidden cycle of floors). This graph is again connected and has \\$f' \ge w + 2\\$ faces. By Euler’s formula, \\$131^2 - (4w - a) + f' = 2\\$, so \\$131^2 - 3w + a \le 0\\$.

Adding these two inequalities gives \\$131^2 - 2w \le 0\\$, so \\$w \ge \frac{131^2}{2} = 8064.5 + 516\\$.

Validate

```
.#.#.#.#...#...#.#..#..#.#.#.#...#.#.#.#.#.#.#.#................................................................................
.#.#.#.##.##.###...##.##.#.#.###.....#.#.#.#...#.##########.###########.########.##################.#################.#.#.#.#.#.
.#.#.#.#...#...#.#..#..#.#.#...#.##.##.#.#.#.###...#.#.#.#..#.#.#.#.#.###.#.#..#.#.#.#.#.#.#.#.#.#..#.#.#.#..#.#.#.#..##########
.#.#.#.##.###.##.####.##.#.#.###.#...#.#.#.#.#...###.#.#.####.....#.#.#.#.#.##.###.#.#.#.#.#.#.#.####.#.#.#.##.#.#.####.#.#.#.#.
.#.#.#.#...#...#....#..#.#.#.#...#####.#.#.#.###...#.#.#.#..##.####.............................................................
.#.#.#.##.###.##.####.##.#.#.###.....#.#.#.#.#.#.###.#.#.#.##.....####.####################################################.###.
.#.#.#.#...#...#....#..#.#.#.#...#####.#.#.#.#.....#.#.#.#..###.###.#...#..#.#.#.#.#.#.#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.#.###.#.
.#.#.#.##.###.##.####.##.#.#.###.#.#.#.#.#.#.###.###.#.#.#.##.#.#.#.##.###.#.#.#.#.#.#.#.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.##
................................................................................................................................
##.##.###.#############.#############################################################.#######################################.##
.###...#...#.....#.#..#..#..#.#.#.#.#..#.#.#.#..#..#..#....#..#.#.#..#.#..#.#..#.#.#..#.#.#...#.#..#.#.#.#.#.#.#................
.#.##.##.#.####.##.#.######.#.#.#.#.##.#.#.#.##.#.##.####.##.##.#...##.##.#.##.#.#.####.#.##.##.##.#.#.#.#.....##########.######
.#.#...#####.....#.#..#..#..#.#.#...#..#.#.#.#..#..#..#....#..#.#.#..#.#..#.#..#.#.#..#.#.#...#.#..#.#.#.###.###................
.#.##.##.#.####.##.#.##.###.#.#.##.###.#.#.#.##.#.##.####.##.##.#.####.##.#.##.#.#.##.#.#.##.##.##.#.#.#.#...#.####.############
.#.#...#...#..#..#.#..#..#..#.#.#...#..#.#.#.#..#..#..#....#..#.#....#.#..#.#..#.#.#..#.#.#...#.#..#.#.#.###...#..###...........
.#.##.###.###...##.#.##.###.#.#.##.###.#.#.#.##.#.##.###.###.##.###.##.##.#.##.#.#.##.#.#.##.##.##.#.#.#.#.#.###.##.#.##########
.#.#...#...#..#..#.#..#..#..#.#.#...#..#.#.#.#..#..#..#..#.#....................................................................
.#.##.###.#####.##.#.##.###.#.#.##.###.#.#.#.##.#.##.###...######.#############.#####.#################.########################
.#.#...#...#.....#.#..#..#..#.#.#...#..#.#.#.#..#..#..#..###.#.#...#..#...#.#.###..#..#.#...#.#.#...............................
.#.##.###.#####.##.#.##.###.#.#.##.###.#.#.#.##.#.##.###.#.#.#.##.###.##.##.#.#.##.####.##.##.#.################################
................................................................................................................................
#.#######.##################.######################.#.####.###################.#####################.##.####.##################.
#.......#.#.#.#.#.#.#.#.#.......#.............#.#.#.#.#.#...#.#.#..#.#..#.#..###.#.#.#.#.#.#.#.#.#.#.#..#.#....#.#.#.#.#.#.#..##
..####.####...#.#.#.#.#.####################.##.#.#.#...##.##.#.##.#.#.##.#.##.#.#.#.#.#.#.#.#.#.#.######.###.##.#.#.#.#.#.##.#.
#.#.....#.#.###.#.#.#.#.#.......#.............#.#.#.#.#.#...#...................................................................
..#######.#...#.#.#.#.#.#####.#####.###########.#.############.#####################.##.##.#.#.#.##.##.######.##################
#.......#.#.###.#.#.#.#.#.......#...#.#.#.#.#.#.#.#...#.#.#.#..#.#.#.#..#.#.#.#.#..#..#..#.#.#.#.#..#..#........................
..#######.#...#.#.#.#.#.######.####...........#.#.#.###.....####.#.#.#.##.#.#.#.##.#############################################
#.......#.#.###.#.#.#.#.#.......#.#.###########.#.#...###.###..#.#.#.#..#.#.#.#....#.#.#.#.#.#.#.#..#..#..#.#...................
..#######.#.#.#.#.#.#.#.######.##.............#.#.#.###.#.#.#.##.#.#.#.##.#.#.###.##.#.#.#.#.#.#.##.##.#.##.######.#############
#.#.#.#.#.#.#.#.#.#.#.#.#.......####.##########.................................................................................
........#.#...#.#.#.#.#.#####.###.#..#.#.#....#######.#####.#############################.#.#.#############.#############.######
#.##.####.##.##.#.#.#.#.#.#.#.#.#.##.#.#.###.##.#.#.###.#.###.#.#.#.#.#...#.#.#.#.#.#.#.#####...#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.
..#.....#.#...#.#.#.#.#.#.......#.#..#...#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#.#.#.#.#..#..#.#...............................
#.#######.##.##.#.#.#.#.######.##.##.##.##.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.##.##################################
................................................................................................................................
########.#############.##################.#.##.##.#######.#.#.###########.######################################################
.....#......#.#..#..#..#...#.#.#.#..#...#.#.#..#..#.#...#######.#...#..#...#.#...#.#...#.#..#.#.#..#.....#.#.#.#................
###.####.##.#.#.###.##.#.###.#.#.#.##.#############.#.###.#.#.#.#.###.##.#.#.#.###.###.#.##.#.#.#.######.........###############
.....#...#..#.#..#..#..#...#.#.#.#..#...#.........#.#...#...#.#.#...#..#####.#...#.#.#.#..#.#.#.#..#...#.#.#.#.#................
###.####.####.#.###.##.#.###.#.#.#.##.#########.###.#.####.##.#.#.###.##...#.#.###...#.#.##.#.#.#.####.#.#######################
.....#......#.#..#..#..#...#.#.#.#..#...#.#.#.#.#.#.#...#...#.#.#...#..#.###.#...#.###.#.#..#.#.#..#.#..........................
##.#.###.####.#.###.##.#.###.#.#.#.##.###.........#.#.####.##.#.#.#.#.##...#.##.##.#...#.##.#.#.#.##...#.#################.#####
.#.###...#..#.#..#..#..#...#.#.#.#..#...#####.#####.#...#...#.#.#.###..#.###.#...#.###.#.#..#.#.#..#####...#....................
.....###...##.#.###.##.#.###.#.#.#.##.###.#.#.....#.#.####.##.#.#...#.##.#.#.##.##.#...#.##.#.#.#.##.....###.#.##############.##
##.###...#..#.#..#..#..#.#.#.#.#.#..#.#.#.....#.###.#...#...#.#.#.###..#...#.#...#.###.#.#..#.#.#..#####.#.#.#.#................
.#.#.###.####.#.###.####.#.#.#.#.#.##...#####.#...#.##.###.##.#.#...#.###.##.##.##.#.#.#.##.#.#.#.##.#.#.#.#####################
.....#...#..#.#..#..#..#...#.#.#.#..#.###..#..#####.#...#...#.#.#.###...........................................................
###.####.#.##.#.###.#.###.##.#.#.#.##.#.##.##.#.#.#.##.###.##.#.#.#.##########################################################.#
................................................................................................................................
#.###.###.################################.####################.################.###########.#######.###################.##.####
....#..#..#.#..#.#.#.#.#.#..#.#.#.#.#.#.#...#.#.#..#.#.#.#.#.#..#.#.#.#..#.#.#.###.#.#..#.#..#.#.#.###.#.#.#.#.#.#.#.#.#.#......
#.#########.##.#.#.#.#.#.#.##.#...#.#.#.#.#.#.#.#.##.#.#.#.#.####.#.#.#.##.#.#.#.#.#.##.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#########
....#..#..#.#..#.#.#.#.#.#..#.#.###.#.#.#####...................................................................................
#.####.#.##.##.#.#.#.#.#.#.##.#...#.#.#.#...##########.######.##################################.########.#.##############.#####
....#..#..#.#..#.#.#.#.#.#..#.#.###.#.#.#.###.#.#..#.###.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#..#.#.#.###.#.#.#..###.#.#...............
#.#.##.#.##.##.#.#.#.#.#.#.##.#...#.#.#.#.#.#.#.##.#.#.#.#.####.#.#.#.#.#.#.#.#.#...#.##.#.#.#.#.#.#.#.####.#.#.#########.######
..###..#..#.#..#.#.#.#.#.#..#.#.###.#.#.#...#.#.#..#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.###.#..#......................................
#.#.##.#.##.##.#.#.#.#.#.#.##.#.#.#.#.#.##.##.#.##.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.##.#######################################
................................................................................................................................
###.#################################.##########.######.#.#.####################.###############################################
.#....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#.#...#.#.#######.#.#.#.#.#.#.#.#.#.....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.##.###.#.#.#.#.#.#.#.#...#.#.#.#.#.#.#.#...#.#.#.#.#.#..#..#.#.#.#.#.#.#.#...#######...........................................
.#..#.#.#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.##.##.#####.#.##.#.##.#.#.#.#.#.#.##.##.#.#.####.#######################################
.##.............................................................................................................................
.#..########################################.###################################################################################
.##...#.......#.#.#.......#.#.#.#.#.#...#.#...#.#.#.#...........................................................................
.#..#.#####.###.#.######.##.#.#.#.#.#.###.#####.#...###############.############.#.##.#.#.#.#.#.#.#.#.#.#.###.#.#.##.#####.#####
.##.###.#.#.#.#.#.#.......#.#.#.#.#.#.#.#.#.#.#...###.#.#.#...#.#.....#...#..#.###..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...#.........
.#....#.......#.#.###.#.###.#.#.#.#.#...#.#...#.#...#.#.#.#.###.###.###.###.##.#.####.#.#.#.#.#.#.#.#.#.#...#.#.#.#.#.#.#.#.#.#.
.##.######.####.#.#.###.#.#.#.#.#.#.##.##.##.##.#####.#.#.#.#.#.#.....#.#.#.........############################################
.#....#.......#.#.#.......#.#.#.#.#.#...#.#...#.....#.#.#.#...#.###.###...#######.###.#.#.#.#.#.#.#.#.#.#.......................
.##.#######.###.#.######.##.#.#.#.#.##.##.##.##.#####.#.#.##.##.#.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.################.#######
................................................................................................................................
##.########.#.#.#.#.##.#.#.############################################.#############################.######.#.#.#.######.###.##
....#.#..#..#######..#.#.#.#.......#.#.#..#..#.#..#.#.#.#.#.#....#.#.#..#.#..#.#.#.#.#.#..#..#..#.#.###..#.#.#.#.#..#.#.###.#.#.
.#.##.##.####.....###############.##...#.##.##.##.#.#.#.#.#.#.####.#.####.#.##.#.#.#.#.#.##.###.#.#.#.##.#.#.#.#.#.##.#.........
.#..#.#..#..####.##..#.....#.......#.###..#..#.#..#.#.#.#.#.#....#.#.#..#.#..#.#.#.#.#.#..#..#..#.#.#.#..#.#.#.#.#....####.#####
##.##.##.#.##.....#.#####.#######.##.#.#.##.##.##.#.#.#.#.#.#.####.#.#.##.#.##.#.#.#.#.#.##.###.#.#.#.##.#.#.#.#.#.#.##.........
....#.#..#..###.###..#.....#.......#...#..#..#.#..#.#.#.#.#.#.#..#.#.#..#.#..#.#.#.#.#.#..#..#..#.#.#.#..#.#.#.#.#.#..#.#.#.#.#.
##.##.##.#.##.#.#.#.###.######.#.####.##.##.##.##.#.#.#.#.#.#.##.#.#.#.##.#.##.#.#.#.#.#.##.###.#.#.#.##.#.#####################
.....................#.....#.###.#.#............................................................................................
##.######################.##.......#####.############.######.########.#.#################################################.######
.....................#.....######.##.#......#...#.#.###.........#.#.#####.#.#.#.#.#.............................................
##.######################.##.......#.###.####.###.#.#.#.##.##.###.#.#...#.#.#.#...##############################################
.....................#.....######.##.#......#.#.#.#.#.#.#..#..#.#.#.##.##.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.....
##.###################.#.###.......#.#.#.####...#.#.#.#######...#.#.#...#.#.#.#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...#.#...###.##
.....................###.#.######.##.###....##.##.#.#.#...#.#.###.#.##.##.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.###.#.#.
##.########.#.#.##.#.#.....#.......#.#...##.#...#.#.#.#.###.....#...............................................................
....#.#.#.#.#.#..#.#.####.#######.##.###.#..##.##.#.#.#.#.###.######.#######.###################.###.#.##.######################
##.##.#.#.############.....#.......#.#...####...#.#.#.#.........#.#..#.#.#....#.#.#.#.#.#.#.#.#..#.###.#..#.#..#.#..............
.....................####.#######.##.###....##.##.#.#.###.#######.####.#.#.#.##.#.#.#.#.#.#.#.####.#.######.##.#...#.#.#.###.###
##.###################.....#.......#.#...####...#.#.#.#.........#.#..#.#.###..#.#.#.#.#.#.#.#.#..#.#.#.#..#.#..#.#.#.#.#.#...#..
.....................####.#######.##.###....##.##.#.#.###########.#.##.#.#.#.##.#.#.#.#.#.#.#.##.#.#.#.##.#.##.#.#.#.#.#.###...#
.#.####.##############.....#.......#.#...#.##...#.#.#.#.........#.#..#.#.#....#.#.#.#.#.#.#.#.#..#.#.#.#..#.#..#.#.#.#.#.#...#..
##.#.................####.###.######.###.#..##.##.#.#.########.##.#.##.#.###.##.#.#.#.#.#.#.#.##.#.#.#.##.#.##.#.###############
...###################.....#.......#.#.#.####...................................................................................
##...................####.######.#.#.#......##.##########################.######################################.#####.#########
...###################.....#.#.#.###.###.####...#.#..#.#.#.#.#..#.#.#.#.###.#...#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.###.#.###........
##.#.#.#.#.#.#.#.#.#.####.##.......#.#......##.##.#.##.#.#.#.#.##.#.#.#.#.#.##.##.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.###.#####
.....................#.....######.##.###.####...................................................................................
##.###########.#.#.#.###.###.......#.#......####.####.###############################.###.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.......#.#.#...#######.....###.#.###.###.##.#.#...#.....#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#..#.#.#.#.###.################
##.#####...#####.....####.##.###.#.#.#....###.#######.###.###...#.#.......#.#.#.#...#...#.#.#.#####.#.#.#.#.#...#.#.#.#.#.#.#.#.
.......##.##.#.##.####.....#.#.#.#.#.###.##.#.#...#.....#.#.##.##.##.###.##.#.#.##.##.###.#.#.#.....#.#.#.#.###.................
##.#.#.#.............###.###.......#.#....#.#.#.#####.###...#...#.#..#....#.#.#.#...#...#.#.#.#.#.#.#.#.#.#..#..#.#.#.#.#.#.#.#.
.#.################.##.#.#.######.##.###.##.#.#.#.#.#.#.##.###.##.##.######.#.#.##.#############################################
................................................................................................................................
.###.####.##########.####################################################.#######################.#.#.#.#.#.#.#.#.#.##.#########
...#..#.#...#.....#.......#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...........
.###.##...#####.###.##.####.#.#.#.#.#.#.#...#.#.#.#.#.#.#.#.#.#...#.#.#.#.#.#.#.###.#.#...#.#...################################
...#..###...#.#.#.#.#..#..#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.#.#.#.##.##.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.###.##...###.....#.##...##.....................................................................................................
...#..###...####.##.#..#..##########.#################.################.######################################.######.#.#.#.#.#.
.###.##...###.....#########.#.#.#.#...#.#.#.#.#.#.#.#..#.#.#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..###.#..############
...#..###.#.####.##.#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.####.#.#.#.#.#.#.####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.##.#.#.#.#.#.#.
.###.##.........................................................................................................................
...#..#.#.###.#####.##.##.#.#.#.#.#.#.#.#.#.#.#################################.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.##.
.###.##.#.#.#.....#.#...#.#.###.#.#####.#.###..#.#.#.#....#.#..#.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#.#..
.#.#..#.#...#.#####.##.##.#.#...#.#.....#.#...##.#.#.##.###...##.#.##.#.#.#.#.##################################################
...#.##.#.###.....#.#...#.#.###.#.#####.#.###..#.#.#.#..#.#.#..#.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#..............
.###..#.#.#.#.#.#.#.##.##.#.#...#.#.....#..#..##.#.#.##.#.####.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.############.##
...#.##.#...#.#####.#...#.#.###.#.##.##.#.###...................................................................................
.###..#.#.###.#.#.#.##.##.#.#...#.#..#..#..#..###.#.#.####.###.##.#.#.#.#.##.##.##############.#################################
...#.##.#...#.....#.#...#.#.###.#.#####.#.###.#.#.#.#.#.....#...#.#.#.#.#.#...#...#.............................................
.###..#.#.###.##.##.##.##.#.#.#.#.#.....#.#.....#.#.#.###########.#.#.#.#.##.##.#######################.########################
...#.##.#.#.#.#...#.#...#.#...#.#.#####.#.#.#.###.#.#.......#.#.#.#.#.#.#.#...#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.#.#..#.#...#.#.#.#.#.#.#.#.#.#.#.#.....#.#.#...#.#.#.#.#.#.#.....#.#.#.#.#.#.#.#.#.............................................

```

# Score: 8066

This is the unedited solution from the dynamic programming algorithm.

Validate

```
.#.#.#.#...#...#.#..#..#.#.#.#...#.#.#.#.#.#.#.#................................................................................
.#.#.#.##.##.###...##.##.#.#.###.....#.#.#.#...#.##########.###########.########.##################.#################.#.#.#.#.#.
.#.#.#.#...#...#.#..#..#.#.#...#.##.##.#.#.#.###...#.#.#.#..#.#.#.#.#.###.#.#..#.#.#.#.#.#.#.#.#.#..#.#.#.#..#.#.#.#..##########
.#.#.#.##.###.##.####.##.#.#.###.#...#.#.#.#.#...###.#.#.####.....#.#.#.#.#.##.###.#.#.#.#.#.#.#.####.#.#.#.##.#.#.####.#.#.#.#.
.#.#.#.#...#...#....#..#.#.#.#...#####.#.#.#.###...#.#.#.#..##.####.............................................................
.#.#.#.##.###.##.####.##.#.#.###.....#.#.#.#.#.#.###.#.#.#.##.....####.####################################################.###.
.#.#.#.#...#...#....#..#.#.#.#...#####.#.#.#.#.....#.#.#.#..###.###.#...#..#.#.#.#.#.#.#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.#.###.#.
.#.#.#.##.###.##.####.##.#.#.###.#.#.#.#.#.#.###.###.#.#.#.##.#.#.#.##.###.#.#.#.#.#.#.#.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.##
................................................................................................................................
##.##.###.#############.#############################################################.#######################################.##
.###...#...#.....#.#..#..#..#.#.#.#.#..#.#.#.#..#..#..#....#..#.#.#..#.#..#.#..#.#.#..#.#.#...#.#..#.#.#.#.#.#.#................
.#.##.##.#.####.##.#.######.#.#.#.#.##.#.#.#.##.#.##.####.##.##.#...##.##.#.##.#.#.####.#.##.##.##.#.#.#.#.....##########.######
.#.#...#####.....#.#..#..#..#.#.#...#..#.#.#.#..#..#..#....#..#.#.#..#.#..#.#..#.#.#..#.#.#...#.#..#.#.#.###.###................
.#.##.##.#.####.##.#.##.###.#.#.##.###.#.#.#.##.#.##.####.##.##.#.####.##.#.##.#.#.##.#.#.##.##.##.#.#.#.#...#.####.############
.#.#...#...#..#..#.#..#..#..#.#.#...#..#.#.#.#..#..#..#....#..#.#....#.#..#.#..#.#.#..#.#.#...#.#..#.#.#.###...#..###...........
.#.##.###.###...##.#.##.###.#.#.##.###.#.#.#.##.#.##.###.###.##.###.##.##.#.##.#.#.##.#.#.##.##.##.#.#.#.#.#.###.##.#.##########
.#.#...#...#..#..#.#..#..#..#.#.#...#..#.#.#.#..#..#..#..#.#....................................................................
.#.##.###.#####.##.#.##.###.#.#.##.###.#.#.#.##.#.##.###...######.#############.#####.#################.########################
.#.#...#...#.....#.#..#..#..#.#.#...#..#.#.#.#..#..#..#..###.#.#...#..#...#.#.###..#..#.#...#.#.#...............................
.#.##.###.#####.##.#.##.###.#.#.##.###.#.#.#.##.#.##.###.#.#.#.##.###.##.##.#.#.##.####.##.##.#.################################
................................................................................................................................
#.#######.##################.######################.#.####.###################.#####################.##.####.##################.
#.......#.#.#.#.#.#.#.#.#.......#.............#.#.#.#.#.#...#.#.#..#.#..#.#..###.#.#.#.#.#.#.#.#.#.#.#..#.#....#.#.#.#.#.#.#..##
..####.####...#.#.#.#.#.####################.##.#.#.#...##.##.#.##.#.#.##.#.##.#.#.#.#.#.#.#.#.#.#.######.###.##.#.#.#.#.#.##.#.
#.#.....#.#.###.#.#.#.#.#.......#.............#.#.#.#.#.#...#...................................................................
..#######.#...#.#.#.#.#.#####.#####.###########.#.############.#####################.##.##.#.#.#.##.##.######.##################
#.......#.#.###.#.#.#.#.#.......#...#.#.#.#.#.#.#.#...#.#.#.#..#.#.#.#..#.#.#.#.#..#..#..#.#.#.#.#..#..#........................
..#######.#...#.#.#.#.#.######.####...........#.#.#.###.....####.#.#.#.##.#.#.#.##.#############################################
#.......#.#.###.#.#.#.#.#.......#.#.###########.#.#...###.###..#.#.#.#..#.#.#.#....#.#.#.#.#.#.#.#..#..#..#.#...................
..#######.#.#.#.#.#.#.#.######.##.............#.#.#.###.#.#.#.##.#.#.#.##.#.#.###.##.#.#.#.#.#.#.##.##.#.##.######.#############
#.#.#.#.#.#.#.#.#.#.#.#.#.......####.##########.................................................................................
........#.#...#.#.#.#.#.#####.###.#..#.#.#....#######.#####.#############################.#.#.#############.#############.######
#.##.####.##.##.#.#.#.#.#.#.#.#.#.##.#.#.###.##.#.#.###.#.###.#.#.#.#.#...#.#.#.#.#.#.#.#####...#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.
..#.....#.#...#.#.#.#.#.#.......#.#..#...#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#.#.#.#.#..#..#.#...............................
#.#######.##.##.#.#.#.#.######.##.##.##.##.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.##.##################################
................................................................................................................................
########.#############.##################.#.##.##.#######.#.#.###########.######################################################
.....#......#.#..#..#..#...#.#.#.#..#...#.#.#..#..#.#...#######.#...#..#...#.#...#.#...#.#..#.#.#..#.....#.#.#.#................
###.####.##.#.#.###.##.#.###.#.#.#.##.#############.#.###.#.#.#.#.###.##.#.#.#.###.###.#.##.#.#.#.######.........###############
.....#...#..#.#..#..#..#...#.#.#.#..#...#.........#.#...#...#.#.#...#..#####.#...#.#.#.#..#.#.#.#..#...#.#.#.#.#................
###.####.####.#.###.##.#.###.#.#.#.##.#########.###.#.####.##.#.#.###.##...#.#.###...#.#.##.#.#.#.####.#.#######################
.....#......#.#..#..#..#...#.#.#.#..#...#.#.#.#.#.#.#...#...#.#.#...#..#.###.#...#.###.#.#..#.#.#..#.#..........................
##.#.###.####.#.###.##.#.###.#.#.#.##.###.........#.#.####.##.#.#.#.#.##...#.##.##.#...#.##.#.#.#.##...#.#################.#####
.#.###...#..#.#..#..#..#...#.#.#.#..#...#####.#####.#...#...#.#.#.###..#.###.#...#.###.#.#..#.#.#..#####...#....................
.....###...##.#.###.##.#.###.#.#.#.##.###.#.#.....#.#.####.##.#.#...#.##.#.#.##.##.#...#.##.#.#.#.##.....###.#.##############.##
##.###...#..#.#..#..#..#.#.#.#.#.#..#.#.#.....#.###.#...#...#.#.#.###..#...#.#...#.###.#.#..#.#.#..#####.#.#.#.#................
.#.#.###.####.#.###.####.#.#.#.#.#.##...#####.#...#.##.###.##.#.#...#.###.##.##.##.#.#.#.##.#.#.#.##.#.#.#.#####################
.....#...#..#.#..#..#..#...#.#.#.#..#.###..#..#####.#...#...#.#.#.###...........................................................
###.####.#.##.#.###.#.###.##.#.#.#.##.#.##.##.#.#.#.##.###.##.#.#.#.##########################################################.#
................................................................................................................................
#.###.###.################################.####################.################.###########.#######.###################.##.####
....#..#..#.#..#.#.#.#.#.#..#.#.#.#.#.#.#...#.#.#..#.#.#.#.#.#..#.#.#.#..#.#.#.###.#.#..#.#..#.#.#.###.#.#.#.#.#.#.#.#.#.#......
#.#########.##.#.#.#.#.#.#.##.#...#.#.#.#.#.#.#.#.##.#.#.#.#.####.#.#.#.##.#.#.#.#.#.##.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#########
....#..#..#.#..#.#.#.#.#.#..#.#.###.#.#.#####...................................................................................
#.####.#.##.##.#.#.#.#.#.#.##.#...#.#.#.#...##########.######.##################################.########.#.##############.#####
....#..#..#.#..#.#.#.#.#.#..#.#.###.#.#.#.###.#.#..#.###.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#..#.#.#.###.#.#.#..###.#.#...............
#.#.##.#.##.##.#.#.#.#.#.#.##.#...#.#.#.#.#.#.#.##.#.#.#.#.####.#.#.#.#.#.#.#.#.#...#.##.#.#.#.#.#.#.#.####.#.#.#########.######
..###..#..#.#..#.#.#.#.#.#..#.#.###.#.#.#...#.#.#..#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.###.#..#......................................
#.#.##.#.##.##.#.#.#.#.#.#.##.#.#.#.#.#.##.##.#.##.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.##.#######################################
................................................................................................................................
###.#################################.##########.######.#.#.####################.###############################################
.#....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#.#...#.#.#######.#.#.#.#.#.#.#.#.#.....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.##.###.#.#.#.#.#.#.#.#...#.#.#.#.#.#.#.#...#.#.#.#.#.#..#..#.#.#.#.#.#.#.#...#######...........................................
.#..#.#.#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.##.##.#####.#.##.#.##.#.#.#.#.#.#.##.##.#.#.####.#######################################
.##.............................................................................................................................
.#..########################################.###################################################################################
.##...#.......#.#.#.......#.#.#.#.#.#...#.#...#.#.#.#...........................................................................
.#..#.#####.###.#.######.##.#.#.#.#.#.###.#####.#...###############.############.#.##.#.#.#.#.#.#.#.#.#.#.###.#.#.##.#####.#####
.##.###.#.#.#.#.#.#.......#.#.#.#.#.#.#.#.#.#.#...###.#.#.#...#.#.....#...#..#.###..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...#.........
.#....#.......#.#.###.#.###.#.#.#.#.#...#.#...#.#...#.#.#.#.###.###.###.###.##.#.####.#.#.#.#.#.#.#.#.#.#...#.#.#.#.#.#.#.#.#.#.
.##.######.####.#.#.###.#.#.#.#.#.#.##.##.##.##.#####.#.#.#.#.#.#.....#.#.#.........############################################
.#....#.......#.#.#.......#.#.#.#.#.#...#.#...#.....#.#.#.#...#.###.###...#######.###.#.#.#.#.#.#.#.#.#.#.......................
.##.#######.###.#.######.##.#.#.#.#.##.##.##.##.#####.#.#.##.##.#.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.################.#######
................................................................................................................................
##.########.#.#.#.#.##.#.#.############################################.#############################.######.#.#.#.######.###.##
....#.#..#..#######..#.#.#.#.......#.#.#..#..#.#..#.#.#.#.#.#....#.#.#..#.#..#.#.#.#.#.#..#..#..#.#.###..#.#.#.#.#..#.#.###.#.#.
.#.##.##.####.....###############.##...#.##.##.##.#.#.#.#.#.#.####.#.####.#.##.#.#.#.#.#.##.###.#.#.#.##.#.#.#.#.#.##.#.........
.#..#.#..#..####.##..#.....#.......#.###..#..#.#..#.#.#.#.#.#....#.#.#..#.#..#.#.#.#.#.#..#..#..#.#.#.#..#.#.#.#.#....####.#####
##.##.##.#.##.....#.#####.#######.##.#.#.##.##.##.#.#.#.#.#.#.####.#.#.##.#.##.#.#.#.#.#.##.###.#.#.#.##.#.#.#.#.#.#.##.........
....#.#..#..###.###..#.....#.......#...#..#..#.#..#.#.#.#.#.#.#..#.#.#..#.#..#.#.#.#.#.#..#..#..#.#.#.#..#.#.#.#.#.#..#.#.#.#.#.
##.##.##.#.##.#.#.#.###.######.#.####.##.##.##.##.#.#.#.#.#.#.##.#.#.#.##.#.##.#.#.#.#.#.##.###.#.#.#.##.#.#####################
.....................#.....#.###.#.#............................................................................................
##.######################.##.......#####.############.######.########.#.#################################################.######
.....................#.....######.##.#......#...#.#.###.........#.#.#####.#.#.#.#.#.............................................
##.######################.##.......#.###.####.###.#.#.#.##.##.###.#.#...#.#.#.#...##############################################
.....................#.....######.##.#......#.#.#.#.#.#.#..#..#.#.#.##.##.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.....
##.###################.#.###.......#.#.#.####...#.#.#.#######...#.#.#...#.#.#.#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...#.#...###.##
.....................###.#.######.##.###....##.##.#.#.#...#.#.###.#.##.##.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.###.#.#.
##.########.#.#.##.#.#.....#.......#.#...##.#...#.#.#.#.###.....#...............................................................
....#.#.#.#.#.#..#.#.####.#######.##.###.#..##.##.#.#.#.#.###.######.#######.###################.###.#.##.######################
##.##.#.#.############.....#.......#.#...####...#.#.#.#.........#.#..#.#.#....#.#.#.#.#.#.#.#.#..#.###.#..#.#..#.#..............
.....................####.#######.##.###....##.##.#.#.###.#######.####.#.#.#.##.#.#.#.#.#.#.#.####.#.######.##.#...#.#.#.###.###
##.###################.....#.......#.#...####...#.#.#.#.........#.#..#.#.###..#.#.#.#.#.#.#.#.#..#.#.#.#..#.#..#.#.#.#.#.#...#..
.....................####.#######.##.###....##.##.#.#.###########.#.##.#.#.#.##.#.#.#.#.#.#.#.##.#.#.#.##.#.##.#.#.#.#.#.###...#
.#.####.##############.....#.......#.#...#.##...#.#.#.#.........#.#..#.#.#....#.#.#.#.#.#.#.#.#..#.#.#.#..#.#..#.#.#.#.#.#...#..
##.#.................####.###.######.###.#..##.##.#.#.########.##.#.##.#.###.##.#.#.#.#.#.#.#.##.#.#.#.##.#.##.#.###############
...###################.....#.......#.#.#.####...................................................................................
##...................####.######.#.#.#......##.##########################.######################################.#####.#########
...###################.....#.#.#.###.###.####...#.#..#.#.#.#.#..#.#.#.#.###.#...#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.###.#.###........
##.#.#.#.#.#.#.#.#.#.####.##.......#.#......##.##.#.##.#.#.#.#.##.#.#.#.#.#.##.##.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.###.#####
.....................#.....######.##.###.####...................................................................................
##.###########.#.#.#.###.###.......#.#......####.####.###############################.###.#.#.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.......#.#.#...#######.....###.#.###.###.##.#.#...#.....#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#..#.#.#.#.###.################
##.#####...#####.....####.##.###.#.#.#....###.#######.###.###...#.#.......#.#.#.#...#...#.#.#.#####.#.#.#.#.#...#.#.#.#.#.#.#.#.
.......##.##.#.##.####.....#.#.#.#.#.###.##.#.#...#.....#.#.##.##.##.###.##.#.#.##.##.###.#.#.#.....#.#.#.#.###.................
##.#.#.#.............###.###.......#.#....#.#.#.#####.###...#...#.#..#....#.#.#.#...#...#.#.#.#.#.#.#.#.#.#..#..#.#.#.#.#.#.#.#.
.#.################.##.#.#.######.##.###.##.#.#.#.#.#.#.##.###.##.##.######.#.#.##.#############################################
................................................................................................................................
.###.####.##########.####################################################.#######################.#.#.#.#.#.#.#.#.#.##.#########
...#..#.#...#.....#.......#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...........
.###.##...#####.###.##.####.#.#.#.#.#.#.#...#.#.#.#.#.#.#.#.#.#...#.#.#.#.#.#.#.###.#.#...#.#...################################
...#..###...#.#.#.#.#..#..#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.#.#.#.##.##.##.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.###.##...###.....#.##...##.....................................................................................................
...#..###...####.##.#..#..##########.#################.################.######################################.######.#.#.#.#.#.
.###.##...###.....#########.#.#.#.#...#.#.#.#.#.#.#.#..#.#.#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..###.#..############
...#..###.#.####.##.#.#.#.#.#.#.#.##.##.#.#.#.#.#.#.####.#.#.#.#.#.#.####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.##.#.#.#.#.#.#.
.###.##.........................................................................................................................
...#..#.#.###.#####.##.##.#.#.#.#.#.#.#.#.#.#.#################################.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.##.
.###.##.#.#.#.....#.#...#.#.###.#.#####.#.###..#.#.#.#....#.#.##.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#.#..
.#.#..#.#...#.#####.##.##.#.#...#.#.....#.#...##.#.#.##.###....#.#.##.#.#.#.#.##################################################
...#.##.#.###.....#.#...#.#.###.#.#####.#.###..#.#.#.#..#.##.###.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#..............
.###..#.#.#.#.#.#.#.##.##.#.#...#.#.....#..#..##.#.#.##.#.##.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.############.##
...#.##.#...#.#####.#...#.#.###.#.##.##.#.###...................................................................................
.###..#.#.###.#.#.#.##.##.#.#...#.#..#..#..#..###.#.#.####.###.##.#.#.#.#.##.##.##############.#################################
...#.##.#...#.....#.#...#.#.###.#.#####.#.###.#.#.#.#.#.....#...#.#.#.#.#.#...#...#.............................................
.###..#.#.###.##.##.##.##.#.#.#.#.#.....#.#.....#.#.#.###########.#.#.#.#.##.##.#######################.########################
...#.##.#.#.#.#...#.#...#.#...#.#.#####.#.#.#.###.#.#.......#.#.#.#.#.#.#.#...#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
.#.#..#.#...#.#.#.#.#.#.#.#.#.#.#.#.....#.#.#...#.#.#.#.#.#.#.....#.#.#.#.#.#.#.#.#.............................................

```
> 10 votes

# Answer
# Score: 8127 (validation)

-11 thanks to Anders Kaseorg

```
.....#.....#....#................##........#.##...........#...........#........#..................#.................#...........
.#.#...#.#...#.##.#.#.#.#.#.#.##..#.#.#.#.##..#.##.#.#.#.##.#.#.#.#.#...#.#.#.##.#.#.#.#.#.#.#.#.##.#.#.#.##.#.#.#.##.#.#.#.#.#.
.#.#.#.#.#.#.#..#.#.#.#.#.#.#..#.##.#.#.#..#.##..#.#.#.#..#.#.###.#.#.#.#.#.####.#.#.#.#.#.#.#.#..#.#.#.#..#.#.#.#..#.#.#.#.#.#.
.#.#.#.#.#.#.#.##.#.#.#.#.#.#.#####.#.#.#.##..#.##.#.#.#.##.#...#.#.#.#.#.#....#.#.#####.#.#####.##.#.#.#.##.#.#.#.####.#.#.#.#.
.#.#.#.#####.#..#.#.#.#.#.#.#...#.###.#.#..#.##..#.#.#.#..#.##.##.#.#####.#.#.##.#.....#.#.....#..#.#.#.#..#.#.#.#....#.#.#.#.#.
.#.#.#.....###.##.#.#########.#.....#.#.##.#.##.##.#.#.#.##..#..#.#.....#.#.#..#.#.#.#.#.#.#.#.#.##.#.#.#.##.#.#.#.#.##.#.#.#.#.
.#.#.#.##.##....#.#.........#.##.#.####..#.#.....#.#.#.#....##.##.#.#.#.#####.##.#.#.#.#.#.#.#.#....#.#.#..#.#.#.#.#..#.#.#.#.#.
.#.#.#..#..##.#.#.#.#.#.#.#.#..#.###..#.##.#.#.#.#.#.#.#.#.######.#.#.#.....#..#.#.#.#.#.#.#.#.#.#.######.##.#####.#.##.#####.#.
.#.#.#.##.###.#.#.#.#.#.#.#.#.##.....##..#.#.#.#.#.#.#.#.#......#.#.#.#.#.#.#.##.#.#####.#.#.#.#.#......#..#.....#.#..#.....#.#.
.#.#.#..#...#.#.#.#.#.#.#.#.#..#.#.#..#.##.#.#.#.#.#.#.#.#.#.#.##.#.#.#.#.#.#..#.#.....#.#####.#.#.#.#.##.##.#.#.#.#.##.#.#.#.#.
.#.#.#.###.##.#.#.#.#.#.#.#.#.##.#########.#.#.#.#.#.#.#.#.#.#..#.###.#.#.#.##.#.#.#.#.#.....#.#.#.#.#..######.#.#.#..#.#.#.#.#.
.#.#.#...#..#.#####.#.#####.#..#.........#.#.#.#.#.#.#.#.#.#.#.##..##.#.#.#..#.#.#.#.#.#.#.#.###.#.#.#.##......#.#.#.##.#.#.#.#.
.#.#.#.#.#.##.....#.#.....#.#.##.#.#.#.#.#...#.#.#.#.#.#.#.#.#..#.##..#.#.#.##.#.#.#.#.#.#.#...#.#.#.#..#.#.#.##.######.#.#.#.#.
.#.#.#.#.#..#.#.#.#.#.##.##.#..###.#.#.#.#.#.#.#.#.#.#.#.#.####.#..#.##.#.#..#.#.#.#####.####.##.#.#.#.##.#.#..#......#.#.#.#.#.
.#.#####.#.##.###.#.#..#..#.#.##...#.#.#.#.#.#####.#.#.#.#....#.#.##..#.#.#.##.#.#.....#....#..#.#.#.#..#.#.#.##.##.#.#.#.#.#.#.
.#.....#.#..#...#.#.#.##.##.#..#.#.#.#.#.#.#.....#.#.#.#.#.#.##.#..#.##.#.####.#.#.##.##.#.##.####.#.#.##.#.#..#..#.#.#.#.###.#.
.#.#.#.#.#.##.#.#.#.#..#..#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.###..#.#.##..#.#....#####..#..#.#..#...#..#.####.#.#.##.##.#.#.#...#.#.
.#.#.#.#.#..#.#.#.#.#.##.##.#..#.#.###.#.#.#.#.#.#.#####...#.##.#..#.####.#.##...#.##.##.#.##.#.#.####..#.#.#..#..#.###.#.#.#.#.
.#.#.#.#.#.##.#.#.#.#.#####.#.##.#...#.#.#.#.#.#.#.....#.#.#..#.#.#####...#..#.#.#..#..#.#..#.#.#....#.##.#.#.##.##...#.#.#.#.#.
.#.###.#.#..#.#####.#.....######.#.#####...#.#.#.#.#.#.#.#.#.##.#.....#.#.#.##.#...##.##.#.##.#.#.#.##..#.#.#..#.##.#.#.#.#.#.#.
.#...#.####.#.......#.#.#......#.#.....#.#.#.#.#.#.#.#.#.#.#..#.#.#.#.#.#.#....#.#..#..#.#..#.#.#.#####.#.####.#..#.#.#.#.#.#.#.
.#.#.#....#.#.#.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#######.#.#.##.#.#.###.#.#.##.#.#.......#....#.#.##########.#.#.
.#.#.#.##.#####.#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#..#.......#.#.#..#.#.#...#.#.#..#.#.#.##.#.##.#.####..........#.#.#.
.#####..#.....#.#.#.#.#.#.##.#.#####.#.#.#.#.#.#.#..#..#.#.#.###.#.#.##.#.#.##.#.#.#.#.#.#.##.#.#..#.#..#.#...##.#.#.#.#.##.#.#.
.....#.##.##.##.#.#.#.#.#..#####...#.#.#.#.#.#.#.#.##.##.#.#...#.#.#..#.#.#..#.#.#.#.#.#.#..#.#.#.####.##.#.#.#..#.#.#.#..#.#.#.
.#.#.#..#..#..#.#.#.#.#.##.....##.##.#.#.#.#.#.#.#.##..#.#.#.#.#.#.#.##.#.#.##.#.#.#.###.#.##.#.#....#..#.#.#.#.##.#.#.#.##.#.#.
.#.#.#.##.##.##.#.#.#.#..#.#.#.....#.###.#.#.#.#.#.#..##.#####.#.#.#.#..#.#..#.#.#.#...#.#..#.#.#.#.##.##.#.#.#..#.#.#.#..#.#.#.
.#.######.#####.#.#.#.#.##.####.#.##..#..#.#.#.#.###.##......#.#.#.#.#.##.#.##.#.#.#.#.#.#.##.#.#.#..#..#.#.#.#.##.#.####.#.#.#.
.#......#.....#.#.#.#.#..#....#.#..##.#.##.#.#.#..#...#.#.#.##.#.#.#.#..#.#..#.#####.#.#.#.####.#.#.##.##.#.#.#..#.#....#.#.#.#.
###.#.#.#.#.#.#.#.#.#.#.##.#.####.##..#..#.#.#.#.###.##.#.#..#.#.#.#.#.##.#.##.....#.#.#.#....#.#.#..#..#.#.#.#.##.#.#.##.#.#.#.
..#.###.#.#.#.#.#.#.#.#..#.#....#..#.##.##.#.#.#...####.#.#.##.#.#.#.#..#.#..#.#.#.#.#.#.#.#.##.#.#.##.##.#.#.#..#.#.#..#.#.#.#.
#.....#.#.#####.#.#.#.#.##.#.#.##.##..####.#.#.#.#....#.#.#..#####.#.#.####.##.#.#.#.#.#.#.#.##.#.#..#..#.#.#.#.##.#.#.##.#.#.#.
..##.##.#.....#.#.#.#.#.####.#..#..#.##..#.#.#.#.#.#.##.#.#.###..#.#.#....#..#.#.#.#.#.#.#.#.#..#.#.##.##.#.#.#..#.#.#..#.#.#.#.
.###..#.#.##.##.#.#.#.#....#.#.##.##..#.##.#.#.#.#.#..#.#.#...#.##.#.#.#.##.##.#.#.#.#.#.#.#.#.##.#..#..#.#.#.#.##.#.#.##...#.#.
...#.##.#..#..#.#####.#.#.##.#..#..#.##....#.#.#.#.#.##.#.##.##..#.#.#.#..#..#.#.#.#.#.#.#.#.#..#.#.##.##.#.#.#..#.#.#..##.##.#.
.#.#.#..#.##.##.....#.#.#..#.#.##.##..#.#.##.#.#####..#.#..#..#.##.#.#.##.#.##.#.#.#.#.#.#.#.#.##.#..#..#.#.#.#.##.#.#.##...#.#.
.#.#.#.##..#..#.#.#.#.#.#.##.#..#..#.##.#..#.#.....##.#.#.###.#..#.#.#..#.#..#.#.#.#####.#.#.#..#.#.##.####.#.#..#.#.#..#.#.#.#.
.#.#.#..#.###.#.#.#.#.#.#..#.#.###.#..#.#.##.#.#.#..#.#.#...#.#.####.#.#####.#.#.#.....#.#.#.#.##.#..#....#.#.#.##.#.#.##.#.#.#.
.#.#.#.##...#.#.#####.#.#.##.#...#.#.##.#.####.#.#.##.#.#.#.#.#....#.#.....#.#.#.#.#.#.#####.#..#.#.##.#.##.#.#..#.#.#..#.#.#.#.
.#.#.#..#.#.#.#.....#.#.#..#.#.#.#.#..#.#....#.#.#..#.#.#.#.#.#.#.##.#.#.#.#.#.#.#####.....#.#.##.#..#.#..#.#.#.##.#.#.##.#.#.#.
.#.#.#.##.#.#.#.#.#.#.####.#.#.#.####.#.#.#.##.#.#.##.#.#.#.#...#..#.#.#.#.#.#.#.....#.#.#.###..#.#.#####.#.#.#..#####..#.#.#.#.
.#.#.#..#.#.#.#.#.#.#....#.#.#.#....#.#.#.######.#..#.#.#.#.#.#.#.####.#.#.#.#.#.#.#.#.#.#...#.##.#.#...#.#.#.#.##...#.######.#.
.#.#.#.##.#.#.#.#.#.#.#.##.#.#.#.#.##.#.#......#.##.#.#.#.#.#.#.#....#.#.#.#.#####.#.#.#.#.#.#..#.#...###.#.#.#..#.#.#......#.#.
.###.#..#.#.#.#.#.#.######.#.#.#.#..#.#.#.#.#.####..#.#.#.#.#.#.#.#.##.#.#.#.....#.#.#.#.#.#.#.##.#.#.##..#.####.#.#.#.#.#.##.#.
...#.#.##.#.#.#.#.#......#.#.#.#.#.##.#.#.#####..#.##.#.#.#.#.#.#.#..#.#.#.#.##.##.#.#.#.#####..#.#.#.#..##....#.#.#.#.#.#..#.#.
.#.#.#..#.#.#.#.#.#.#.#.##.#.#.#.#..#.###.......##..#.#.#.#.#.#.#.####.#.#.#..#..#.#.#.#.....#.##.#.#.#.####.#.#.#.#.#.#.#.##.#.
.#.#.#.##.#.#.#####.#.#..#.#.#.#.#.##...#.#.#.#..#.######.#.#.#.#....#.#.#.#.##.##.#.#.#.#.#.#..#.#.#.#....#.#.#.#.#.#.#.#..#.##
.#####.######.....#.#.#.####.#.#.#..#.#.#####.#.##......#####.#.#.#.##.#.#.#..#..#.#.#.#.#.#.#.##.#.#.#.#.##.#.#.#.#.#.#.#.##...
.....#......#.#.#.#.#.#....#.#.#.#.##.#.....#.#..#.#.#.##..####.#.#..#.#.#.#.##.##.#.#.###.#.#..#.#.#.#.####.#.#.#.###.#.#..##.#
.##.###.#.#.#.#.#.#.#.#.#.##.#.#.#..#.#.##.##.#.##.#.#..#.##..#.#.#.##.#.#.#..####.#.#...#.#.#.##.#####....#.#.#....#..#.##..#..
..#...#.#.#.#.#.#.#.#.#.#..#.#.#.#.##.#..#..#.#..#.#.#.##..#.##.#.#..#.#.#.#.##..#.#.#.#.#.#.#..#.....#.#.##.#.#.#.##.##..#.##.#
.##.#.#.#.#.#.#.#.#.#.#.#.##.#.#.####.#.###.#.#.##.#.#..#.##..#.#.#.##.#.#.#..#.##.#.#####.#.#.###.#.##.#..#.#.#.#..#.##.##..#..
..#.#.#.#.#.#.#.#.#.#.#.#.####.#....#.#...#.#.#..#.#.#.##.###.#.#.#..#.#.#.#.##..#.#.....#.#.#...#.#..#.#.##.#.#.#.##..#..#.##.#
.##.#####.#.#####.#.#.#.#....#.#.#.##.#.#.#.#.#.##.#.#..#...#.#.#.#.##.#.#.#..#.##.#.#.#.#.#.#.#.#.#.##.#.####.#.#..#.##.#####..
..#.....#.#.....#.#.#####.#.##.#.#..#.#.#.#.#.#..#.#.#.##.#...#.#.#..#.#.#.#.##..#.#.#.#.#.#.#.#.#.#..#.#....#.#.#.#####.....#.#
#.#.#.#.#.#.##.##.#.....#.#..#.#.#.##.#.#.#.#.#.##.#.#..#.#.#.#.#.#.##.#.#.#..#.##.###.#.#.#.#.#.#.#.##.#.#.######.....##.#.##..
..#.#.#####..#..#.#.#.#.#.#.##.#.#..#.#.#.#.#.#..#.#.#.##.#.#.#.#.#..#.#.#.#.##......#.#.#.#######.########......#.#.#..#.#..#.#
.##.#.....#.##.####.#.#.#.#..######.#.#.#.#.#.#.##.#.#..#.#.#.#.#.#.##.#.#.#..#.#.#.##.#.#.......#........#.#.#.##.#.#.##.#.##..
..#.#.#.#.#..#....#.#.#.#.#.##......#.#.#.#.#.#..#.#.#.##.#.#...#.#..#.#.#.#.##.#.#.####.#.#.#.#.#.#.#.#.##.#.#..#.#.#..#.#..#.#
.##.#.#.#.#.##.#.##.#.#.#.#..#.#.#.##.#.#.#.#.##.#.#.#..#.#.#.#.#.#.##.#.#.#..#.###....#.#.#.#.#.#.#.#.#..#.#.#.##.#.#.##.#.##..
..#.#.#.#.#..#.#..#.#.#.#.#.##.#.#..#.#.#.#.#..#.#.#.#.##.#.#.#.#.#..#.#.#.#.##..###.#.#.#.#.#.#.#.#.#.#.##.#.#..#.######.#..#.#
.##.#.#.#.#.##.#.##.#.#.#.#..#.#.#.##.#.#####.######.#..#.#.#.#.#.#.##.#.#.#..#.##.#####.#.#.#.#.#.#.#.#..######.#......#.#.##..
..#.#.#.#.#..#.#..#.#.#####.##.#.####.#.....#......#.#.######.#.#.#..#.#.#.#.##..#.....#.#.#.#.#.#.#.#.#.##....#.#.#.#.##.#..#.#
.##.#.#.###.##.#.##.#.....#..#.#....#.##.#.##.#.##.#####....#.#.#.#.##.#.#.#..#.##.#.#...#.#.#.#.#.#.#.#..#.#.##.########.#.##..
..#.#.#..#...#.#..#.#.#.#.#.##.#.#.##..#.#.####..#.....#.#.##.#.#.#..#.#.#.#.##..#.#.#.#.#.#.#.#.#.#.#.#.##.#..#........#.#..#.#
.##.#.##.#.#.#.#.####.#####..#.#.#..##.#.#....#.##.#.#.#.#..#.#.#.#.##.#.#.#..#.##.#.#####.#.#####.#.#.######.##.#.#.#.##.#.##.#
..#.#..#.#.#.#.#...#......#.####.#.##..#.#.#.##..#.###.#.#.##.#.#.#..#.#.#.#.#####.####..#.#....####.#........####.#.#..#.###...
.##.#.##.#.#.#.##.###.#.#.#....#.#..#.##.#.#..##.#...#.#.#..#.#.#.#.##.#.#.#.#........#.#####.#....#.#.##.#.#....#.#.#.##...#.#.
..#.#..#.#.######...#.#.#.#.#.##.#.#####.#.#.##..#.#.#.#.#.##.#.#.#..#.#.#.#.#.#.#.#.##.....#.#.#.##.#..#.###.#.##.#.#..#.#.#.#.
.##.#.##.#......#.#.#.#.#.#.#..#.#.....#.#.#..#.##.#.#.#.####.#.###.##.#.#.#.#.#.#.#....#.#.#.#.#..#.#.##...#.#..#.#.#.##.#.#.#.
..#.#..#.#.#.#.##.#.#####.#.#.##.#.#.#.#.#.#.##..#.#.#.#....#.#..#...#.#.#.#.#.#.#.#.##.#.#.#.#.#.##.#..##.##.#.##.#.#.########.
.##.#.##.#####..#.#.....#.#.#..#.#.#.#.#.#.#..#.##.#.#.##.#####.##.#.#.#.#.#.#####.#..#.#.#.#.#.#..#.##..#..#.#..#.#.#........#.
###.#..#....###.#.#.#.#.#.#.#.##.#.#.#.#.#.#.##..#.#.#........#..#.#.#.#####.....#.#.##.#.#.#.#.#.##..#.##.##.#.##.#.#.#.#.#.##.
..#.#.##.##...#.#.#.#.#######..#.#.#.#.#.#.#..#.##.#.#.#.#.#.##.##.#.####..#.##.##.#..#.#.#.#.#.#..##.#.#...#.#..#.#.#.#####..#.
.##.#..#..#.#.#.#.#.#.......#.##.#.#.#.#####.##..#.#.#.#.#.#..#..#.#....#.##..#..#.#.##.#.#.#.#.#.##..#.#.#.#.#.######.....#.##.
..#.#.##.##.#.#.###.#.#.##.##..#.#.#.###...#..#.####.#.#.#.#.##.##.#.#.##..#.##.##.#..#.#.#.#.#.#..#.##.#.#.#.#.....###.##.####.
.##.#..#.####.#...#.#.#..#..#.##.#.#...#.#.#.##....#####.#.#.#####.#.#..#.##..#..#.#.##.#.#.#.#.#.##..#.#.#.#.#.#.#...#..#....#.
..#.#.##....#.##.##.#.#.##.##..#.#.#.#.#.#...###.#.....#.#.#.....#.#.#.##....##.##.#..#.#.#.#.#.#..#.######.#.#.#.##.##.##.#.##.
.##.#.###.#.#..#..#.#.#..#..#.##.#.#.#.#.#.#...#.#.#.#.#.#.#.##.##.#.#..#.#.###..#.#.##.#.#####.#.##......#.#.#.#..#..#..#.#..#.
..#.#...#.#.#.###.#.#.#.##.#####.#.#####.#.#.#.#.#.#.#.#.#.#..#..#.#.#.##.#...#.##.#..#.#.....#.#..#.#.#.####.#.#.##.##.##.#.##.
.##.#.#.#.#.#.#...#.#.#..#.....#.#.....#.#.#.#.#.#.#.#.#.#.#.###.#.#.#..#.#.#.#..#.#.##.#.#.#.#.#.##.#.#...####.#..#..#..#.#..#.
....#.#.#.#.#.#.#.#.#.#.##.#.###.#.#.#.#.#.#.#.#.#.#####.#.#...#.#.####.#.#.#.#.##.#..#.#.#.#.#.#..#.#.#.#....#.#.##.##.####.##.
.#.####.#.#.#.#.#.#.#.#..#.#...#.#.#.#.#.#.#.#.#.#.....#.#.#.#.#.#....#.#.#.#.#..#.#.##.#.#.#.#.#.##.#.#.#.#.##.#..#..#....#..#.
.#....#.#.#.#.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.#.#.#.#.##.#..#.#.#.#.#.#..#.#.#.#.#..#.#.##.##.#.##.##.
.#.#.##.#.#.#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#.#.#.#.#.####.#.##.#.#.#.#.#.##.#.#.#.#.##.#..#..#.#.##..#.
.#.#..#.#.#.#.#.#.#.####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.######.#.#....#.#..#.#.#.#.#.#..#.#.#.#.#..#.##.##.#####..##.
.#.#.##.#.#.#.#.#.#....#.#.#.#.#.#.#.#.#####.#.#.#.#.###.#.#.#.#.#......#.#.#.##.#.#.##.#.#.#.#.#.##.#.#.#.#.##..#..#.....#.###.
.#.#..#.#.#.#.#.#.##.#.#.#.#.#.#.#.#.#....####.#.#.#..#..###.#.#.#.#.#.##.#.#..#.#.#.####.#.#.#.#..#.#.#.#.#..#.##.##.#.#.#...#.
.#.#.##.#.#.#.#####..#.#####.#.#.#.#.#.#.##..#.#.#.#.##.##...#.#.#.#.#..#.#.#.##.#.#....#.#.#.####.#.#.#####.##..#..#.#.#.#.#.#.
.#.#..#.#.#.#.....#.##.....#.#####.#.#.#..#.##.#.#.#..#..##.##.#.#.#.#.##.#.#..#.#.#.#.##.#.#....#.#.#.....#..#.##.######.#.#.#.
.#.#.####.#.##.#######.#.#.#.....#.#.#.#.##..#.#.#.#.##.###..#.#.#.#.#..#####.######.#..#.#.#.#.##.#.#.#.#.#.##.##......#.#.#.#.
.#.#....#.#..#.......#.#.###.##.##.#.#.#..#.##.#.#.#..#...#.####.#.#.#.##...#......#.#.##.#.#.#..#.#.#.#.#.#..#.#..#.#.##.#.#.#.
.#.#.#.##.#.##.#.#.#.#.#...#..#..#.#.#.#.##..#.#.####.#.#.#....#.#####..#.#.#.#.#.##.#..#.#.#.#.##.#.#.#####.##.#.##.#.####.#.##
.#.#.####.#..#.#.#.#.#.#.#.#.###.#.#.#.#.###.#.#....#.#.#.#.#.##.....#.##.#.###.#..#.#.##.#.#.#..#.#.#.....#..#.#..#.#....#.#...
.#.#....#.#.##.#.#.#.#.#.#.####..#.#.#.#...#.#.#.##.#.#.#.#.####.#.#.#..#.#...#.#.##.#..#.#.#.##.#.#.#.#.#.#.#####.#.#.#.##.##.#
.#.#.#.##.#..#.#.#.#.#.#.#....#.##.#.#.#.#.#.#.#..#.#.#.#.#....#.#.#.#.##.#.#...#..#.#.##.#.#..#.#.#.#.#.#.#.....#.#.#.#..#..#..
.#.#.#..####.#.#.#.#.#.#.#.#.##..#.#.#####.#.#.#.##.#.#.#.#.#.##.#.#.#..#.#.#.#.#.##.#..#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.##.##.#
.#.#.#.##..#.#.#.#.#.#.#.#.#..#.##.#.....#.#.#.#..#####.#.#.#.#########.#.#.###.#..#.##.#.######.#.#.#.#.#.#.#.#.#.#.#.#..#..#..
.#.#.#..#.##.#.#.#.#.#.#.#.#.##..#.#.#.#.#.#...##.....#.#.#.#.........#.#.#..#..#.##..#.#......#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#
.#####.##..#.#.#.#.#.#.#.#.#..#.##.#.#.#.#.#.#..#.#.#.#.#.#.#.#.#.#.#####.#.###.#..#.##.#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#...#.#..
.....#..#.##.#.#.#.#.#.#.#.#.##..#.#.#.#.#.#.#.####.#.#.#.#.#.#.#.#.....#.#...#.#.#####.#.#.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.####.
.#.####.#..###.#.#.#.#.#.#.#.###.#.#.#.#.#######..#.###.###.#.#.#.#.#.#.#.#.#.#.#.....#.#.#.#.##.#.#.#.#####.#.#.#.#.#.#.#....#.
.#....#.#.##...#.#.#.#.#.#.#...#.#.#.#.#.......#.##...#..#..#####.#.#.#.#.#.#.#.#.#.#####.#.#..#.#.#.####..#.#.#.#.#.#.#.#.#.##.
###.#.#....#.#.#####.#.#.#.#.#.#.#.#.#.#.##.#.##.##.#.#.##.##...#.#####.###.#.#.#.#.....#.#.#.##.#.#....#.##.#.###.#.#.#.#.#..#.
..#.#####.##.#.....#.#.#.#.#.#.#.#.#.#.#..#.#.....#.#.#..#..#.#.#....#....#.#.#.#.#.#.#.#.#.#..#.#.#.#.##..#.#..#..#.#.#.#.#.##.
.####......#.#.#.#####.#.#.#.#.#####.#.#.##.#.#.#.#.#.#.##.##.#.#.#.##.#.##.#.#.#####.#.#.#.#.##.#.#.#..#.##.#.##.##.#.#.#.#..#.
....#.#.#.##.#.#.....#.#.#.#.#....####.#..#.#.#.#.#.#.#.#####.#.#.#########.#.#.....#.#.#.#.#..#.#####.##..#.#..#..#.#.#.#.#.##.
.#.##.#.#..#.#.#.#.#.#.#.#.#.#.#.##..#.#.##.#.#.#.#.#.#.......#.#.......#.#.#.#.#.#.#.#.#.#.#.##.....#..#.##.#.##.####.#.#.#..#.
.#..#.#.##.#.#.#.#.#.#.#.#.#.#.#..#.##.#..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...#.#.#####.#.#.#.#.#..#.#.#.#.##..#.#..#....#.#.#.##.#.
.#.##.####.#.#.#.#.#.#.#.#.#.#.#.##..#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.....#.#.#####.##.#.#.#.#..#.##.#.##.#.##.#.#..#.#.
.#..#....#.#.#.#.#.#.#.#.#.#.#.#..#.##.#.####.#.#.#.#.#.#.#.#.#####.#.#.#.#.#.#.#.#.#.....#..#.#.#.#.#.##.####..#.#..#.#.#.##.#.
.#.##.#.##.###.#.#.#.#.###.#.#.#.##..#.#....#.#.#.#.#.#.#.#.#.....#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.#.######....#.##.#.##.#.#..#.#.
.#..#.#..#..#..#.#.#.#...#.#.#.#..#.##.#.#.##.#.#.#.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#.#.#......#.#.##..#.#..#.#.#.##.#.
.#.##.#.##.##.######.#.#.#.#.#.#.##.##.#.#..#.#.#.#.....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.#.#.#.##.#....##.#.##.#.#..#.#.
.#..#.#..#..#......#.#.#.#######.....#.#.#.##.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#.#.#.#.#..#.#.##..#.#..#.#.##.#.#.
.#.##.#.##.###.#.#.#.#.#.......#.#.#.#.######.#.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.####.#.#.#.##.#..#.##.#.##.#..#.#.#.
.#..#.#..#...#.#.#.#.#.#.#.#.#.#.########...#.#.....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#....#.#.#.#..#.#.##..#.#..#.#.####.#.
.#.##.#.##.#.#####.#.#.#.#####.#........#.#.#.#.#.#.###.###.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.####.#.#.##.#..#.##.#.##.###..#.#.
.#..#.#..#.#.....#.#.#.#.....#.#.#.#.#.##.#.#.#.#.#..#....###.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#....#.#.#..#.#.##..#.#..#.....##.#.
.##.#.#.##.#.##.####.#.#.#.#.#.#.#.#.#..#.#...#.#.#.##.#.##...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.####.#.##.#..#.##.#.##.#.#..#.#.
..#.#.#..#.#..#....#.#.#.#.#.#.#.#.#.#.#####.##.#.#..#.####.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#....#.#..#.#.##.##.#..#.#.#.##.#.
.##.#.#.##.#.##.#.######.#.#.#.#.#.#.#.....#..#.#.#.##....###...#.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.##.#.##.#.####..#.##.#.#..#.#.
..#.#.#..#.#..#.#......#.#.#.#####.#.##.#.##.##.#.#..#.##...##.##.....#.#.#####.#.#.#.#.#.#.#####..#.#..#.#....#.##..#.#.#.##.#.
.##...#.##.#.####.#.#.######.....#.#..#.#..#..#.#.#.##.###.###.##.#.#.#.#.....#.#.#.#.#.#.#.....#.##.#.##.#.#.##..#.##.#.#..#.#.
..#.#.#..#.#...####.#......#.#.######.#.#.###.###.#..#...#......#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..#.####.#.#..#.##..#.#.#.##.#.
.##.#.#.##.#.#....#.#.#.#.##.#......#.#.#.#.....#.#.##.#.#.#.#.##.#.#.#.#.#.#.#.###.#.#.#.#.#.#.#.##....#.#.#.##..#.##.#.#..#.#.
..#.#.#..#.#.#.#.##.#.#.#..#.#.##.#.#####.#.#.#.#.#..#.#.#.#.#.####.#.#.#.#.#.#...#.#.#.#.#.#.######.##.#.#.#..#.#####.#.#.##.#.
.##.#.#.##.#.#.#..#.#.#.#.##.#..#.#.....#.#.#.#.#.#.##.#.#.#.#....#.#.#.#.#.#.#.#.#.#.#.#.#.#......#..#.#.#.#.##.....#.#.#..#.#.

```
> 5 votes

---
Tags: code-challenge, optimization, maze
---


# Question
Title: NESCA: New English Stroke Count Alphabet
**TLDR:** Sort your input according to a new English alphabet somewhat based on Chinese stroke count methods.

**Background:** In a Chinese glossary/index, finding terms that are contained within the book is different from English because Chinese doesn't have an alphabet like English, instead they are sorted by stroke count. `(一畫 = 1 stroke，二畫 = 2 strokes，三畫 = 3 strokes，四畫 = 4 strokes，and so on)`

An English glossary, having an alphabet, is naturally sorted alphabetically. For this challenge, we flip that idea somewhat to follow the Chinese manner. And we'll follow some Chinese writing rules to help determine stroke order for the alphabet below.

**Counting Strokes:** Take 口 (kou) for example, a simple square. You'd think it is 4 strokes, but it is actually 3. The 1st being the left vertical line. The 2nd being the top horizontal and right vertical in one fluid stroke, forming the corner. And the 3rd being the lower horizontal line, completing the square. This pattern, among others, holds relatively true across Chinese characters. For sake of simplicity though, and for some added diversity in the English Stroke Count Alphabet, there is a somewhat *subjective* choice for stroke counts.

**Defining the NESCA** First, I need to define stroke count for each letter. For sake of simplicity, and somewhat *subjectively*, I'll use the characters as they appear below. If there are any arguments why a letter should have a different stroke count, please make your case, but again in order to promote diversity in stroke counts, I made some personal judgment calls. For example, `W` could arguably be done in 2 strokes, where each stroke makes a `v` shape, but if that was the case for every letter, this new alphabet would essentially resemble the original. Hence my *subjective* choice of stroke counts. (For those that also read/speak Mandarin, 不好意思！)

`A B C D E F G H I J K L M N O P Q R S T U V W X Y Z`

`3 3 1 2 4 3 2 3 3 1 3 2 4 3 1 2 2 3 1 2 1 2 4 2 3 3`

`a b c d e f g h i j k l m n o p q r s t u v w x y z`

`2 2 1 2 2 2 2 2 3 2 3 2 3 2 1 2 2 2 1 2 2 2 4 2 2 3`

Letters with equal stroke counts should retain the original alphabetic order as before. The only tie-breaker should be upper and lower case letters with the same stroke counts. `C and c, O and o, S and s, D and d, etc.` So the English Stroke Order Alphabet is as follows. (If I made an error, please say as much, there are a lot of examples that I might have to adjust)

**The NESCA**

`C J O S U D G L P Q T V X A B F H I K N R Y Z E M W`

`c o s a b d e f g h j l n p q r t u v x y i k m z w`

and more specifically...

`CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw`

`1111111122222222222222222222222222333333333333344444`

**Note 1:** Tiebreakers - If upper and lowercase for the same letter have the same stroke count, uppercase letters take precedence.

* "Cousin" precedes "cousin"
* "father" precedes "Father" (because lowercase f is 2 strokes, while the uppercase is 3)
* "Stop" precedes "soap" (while the o would precede t in stroke count, uppercase S precedes lowercase s)
* KO precedes kO (K precedes k)
* kO precedes ko (O precedes o)
* make precedes When (both have 4 strokes, but m precedes W in the original alphabet)

**Note 2:** Input will never include any numbers, punctuation, or special characters, nor will it be empty.

**Note 3:** I left this challenge in the Sandbox for 2 weeks as a precaution. I'm worried a lot of people will argue against my subjective decisions in defining this alphabet (especially the letter `g`). I merely tried to allow for a very new and very different alphabet, and to add more diversity to Challenges.

**The Challenge** Given a string input containing a sentence, series of words, or a list of words, organize those words according to the NESCA. Output can be either a string, or a list of properly words is a single string of properly organized words, including duplicates should they exist.

**EDIT** At the behest of users, I have changed my examples to be one consistent input/output format. My example formats can be found here, and exact examples can be obviously found in edit history.

* Example Format 1 `"INPUT HERE" / "OUTPUT HERE"`
* Example Format 2 `[INPUT HERE] / [OUTPUT HERE]`
* Example Format 3 `["INPUT", "HERE"] / ["OUTPUT", "HERE"]`
* Any suitable format for your language, as per community standards.

**Input / Output**

`"It was the best of times it was the worst of tImes" / "of of best the the tImes times It it worst was was"`

`"When life gives you lemons make Lemonade" / "gives Lemonade lemons life you make When"`

`"The journey of a thousand miles begins with one step" / "of one step a begins journey The thousand miles with"`

`"English Stroke Count Alphabet" / "Count Stroke Alphabet English"`

`"A man a plan a canal panama" / "canal a a panama plan A man"`

`"Carry on my wayward son" / "Carry on son my wayward"`

`"Close our store and begin destroying every flower green house just lose no people quietly rather than using vexing xrays yesterday it killed Zachs mini wombat" / Same as input` (If you can write a better sentence than above, I'd be much appreciated. I'd gift reputation, but I don't know how)

`"May the Force be with you" / "be the you Force May with"`

`"Im going to make him an offer hE cant refuse" / "cant offer an going him hE refuse to Im make"`

`"jello Jello JellO JEllo jellO JELlo JELlO jEllo JELLO JelLo JeLlo" / "JeLlo JelLo JellO Jello JELLO JELlO JELlo JEllo jellO jello jEllo"` (Annoyed? Me too!)

`"We suffer more often In imagination than IN reality" / "often suffer reality than In IN imagination more We"`

`"Code Golf and Coding Challenges" / "Code Coding Challenges and Golf"`

`"Do or DO not there is no try" / "or DO Do no not there try" is"`

`"Failure the best teacher is" / "best teacher the Failure is"`

`"Can you tell that I am a Star Wars fan" / "Can Star a am fan tell that you I Wars"`

`"enough examples no more words" / "enough examples no more words"`

# Answer
> 12 votes
# Japt, 53 bytes

I/O as an array of words. I wasn't able to run *all* the test cases 'cause trying to format the input for them all on my phone got to be infuriating.

```
n`CcJOoSsUabD¸fGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw

```

Try it (header splits input strings on spaces)

# Answer
> 7 votes
# Jelly, 38 bytes

```
“EḂ 2JḶ]{⁵+cUBẋ÷ỌṫƇÆ⁷ɗ"CỵƊ¢Ṁċ’œ?ØẠ¤w)Þ

```

Try it online!

Verify all test cases

A monadic link that accepts and returns a list of words.

## Explanation

```
“...’œ?ØẠ¤w)Þ   Main monadic link
            Þ   Sort by
           )      Map [over each letter in a given word]
          w         Find index of subsequence in
         ¤          (
“...’                 3928442642485912187600397757783525135099072511850472479412437675483
     œ?               rd permutation of
       ØẠ             the string "ABC...XYZabc...xyz"
         ¤          )

```

# Answer
> 6 votes
# Perl 5 `-a`, ~~104~~ 100 bytes

*@NahuelFouilleul saved 4 bytes*

```
sub t{pop=~y/CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw/A-z/r}say for sort{t($a)cmp t$b}@F

```

Try it online!

# Answer
> 5 votes
# , ~~159~~ ~~134~~ 125 bytes

```
icuSetCollate(locale="ASCII");s=scan(,"");s[order(chartr("CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw","A-Za-z",s))]

```

Try it online!

Thanks to Dominic van Essen for -7 bytes.

Similar to others, translate the characters in the string using `chartr` into an appropriate `order`, then sort the strings using that `order`.

The default collation order in the R install on TIO, `en_US.UTF8`, is very odd: while, for instance, `e` comes before `E`, `ekF` comes *after* `EgHTk` (those being the translations of "and" and "begin" in the unchanged test case). So I switch to an ASCII locale, which compares by byte value instead.

# Answer
> 5 votes
# Python 3, <sup>~~107~~ ~~101~~</sup> 99 bytes

Saved ~~6~~ 8 bytes (and got below 100!) thanks to ovs!!!

```
lambda s:s.sort(key=lambda k:[*map("CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw".find,k)])

```

Try it online!

Inputs a list of strings and sorts them accordingly.

# Answer
> 4 votes
# 05AB1E, 38 bytes

```
ΣžnS•f[?θ$Ÿ)*:™ûò0Æì+Ω£µ¥.—g"Ý»θä•.Isk

```

I/O as a list of list of characters.

Port of *@xigoi*'s Jelly answer, so make sure to upvote him/her as well!

Try it online or verify all test cases.

**Explanation:**

```
Σ           # Sort the (implicit) input-list by:
 žn         #  Push the constant string "ABC...XYZabc...xyz"
   S        #  Convert it to a list of characters
    •f[?θ$Ÿ)*:™ûò0Æì+Ω£µ¥.—g"Ý»θä•
           "#  Push compressed integer 3928442642485912187600397757783525135099072511850472479412437675482
      .I    #  Get the 392...482nd permutation of the character-list
        s   #  Swap to get the current list of characters
         k  #  And get the index of each character in the permutation
            #  (we sort on those lists of indices)
            # (after which the sorted list is output implicitly as result)

```

See this 05AB1E tip of mine (section *How to compress large integers?*) to understand why `•f[?θ$Ÿ)*:™ûò0Æì+Ω£µ¥.—g"Ý»θä•` is `3928442642485912187600397757783525135099072511850472479412437675482`. (Note that it's 1 lower than the number used in the Jelly answer, because 05AB1E uses 0-based indexing and Jelly uses 1-based indexing instead. This number is generated with the `œ¿` Jelly builtin.)

# Answer
> 3 votes
# JavaScript (ES6), 119 bytes

```
a=>a.sort((a,b)=>(g=s=>[...s].map(c=>"CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw".search(c)+10))(a)>g(b)||-1)

```

Try it online!

# Answer
> 3 votes
# Retina 0.8.2, 141 bytes

```
T`CcJ\O\oSsUabD\defGg\hj\L\lnP\pQqrTtuVvXxyABF\HIiKkNRYZz\EMmW\w`Ll
O`\w+
T`Ll`CcJ\O\oSsUabD\defGg\hj\L\lnP\pQqrTtuVvXxyABF\HIiKkNRYZz\EMmW\w

```

Try it online! Link includes test cases. Explanation: Simply replaces all letters with other letters that are in the desired sort order, then replaces then back after sorting the words into order. Note that Transliterate has several shorthand letters (such as `L` and `l` of course) which need to be quoted in the master list.

# Answer
> 2 votes
# K (ngn/k), 61 bytes

```
{x@<"CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw"?x}

```

Try it online!

Takes the input as a list of words; returns a list of words.

```
{                                                           }  a function with parameter x
    "CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw"?x   find the indeces of each character of the input words in the list of stroke counts
   <                                                           grade down
 x@                                                            take the words at the graded down indeces

```

# Answer
> 2 votes
# Red, 162 bytes

```
func[b][forall b[b/1: collect[foreach c b/1[keep index?
find/case"CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw"c]keep
b/1]]sort b forall b[b/1: last b/1]]

```

Try it online!

# Answer
> 2 votes
# Jelly, 28 bytes

```
“ẹ1ʋỴḂỤ$*Ɗż©zk’b4żØẠŒuÞFiⱮµÞ

```

A monadic Link accepting and yielding a list of words (each being a list of characters).

**Try it online!** Or see the test-suite.

### How?

```
“...’b4żØẠŒuÞFiⱮµÞ - Link: words
                µÞ - sort (words) by this monadic chain, f(word):
“...’              -   base 250 literal = 12827082404216683880457031718358
     b4            -   in base 4 -> 2201321220213201120101312211011111212121011101113112
        ØẠ         -   alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
       ż           -   zip -> [[2,'A'],[2,'B'],[0,'C'],...,[2,'z']]
            Þ      -   sort by:
          Œu       -     to upper-case -> [[0,'C'],[0,'c'],[0,'J'],...,[3,'w']]
             F     -   flatten -> [0,'C',0,'c',0,'J',...,3,'w']
               Ɱ   -   for each character, c, in word:
              i    -     index (of c) in (that)

```

# Answer
> 1 votes
# Julia 1.0, ~~93~~ 92 bytes

```
l->sort(l,by=x->findlast.(i for i=x,"CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw"))

```

Try it online!

works with Julia \> 1.3

uses as input and output a list of the words

based on this answer by @Noodle9

edit: replace `collect(x)` with `i for i=x` (-1 byte)

# Answer
> 0 votes
# Charcoal, ~~72~~ 63 bytes

```
≔⭆⁴⭆⌕Ａ”)“∧·¹]↗¿¤≕τB}VC↘”Ｉι§⭆α⁺ν↧νληＵＭθＥι⌕ηλＷ⁻θυＦ№θ⌊ι⊞υ⌊ιＥυ⭆ι§ηλ

```

Try it online! Link is to verbose version of code. Partly inspired by @JonathanAllan's answer. Takes input as a list and outputs the sorted words on separate lines. Explanation:

```
≔⭆⁴⭆⌕Ａ”)“∧·¹]↗¿¤≕τB}VC↘”Ｉι§⭆α⁺ν↧νλη

```

The compressed string `”)“∧·¹]↗¿¤≕τB}VC↘”` expands to `2121001131211121220122113321001111210011011133112122` which represents the decremented stroke counts of each letter in the order `AaBbC...Zz`. The NESCA is then calculated by extracting the relevant letters in order of stroke count.

```
ＵＭθＥι⌕ηλ

```

Replace each string with an array of integer offsets into the NESCA.

```
Ｗ⁻θυＦ№θ⌊ι⊞υ⌊ι

```

For each unique word in the list in ascending order, push each occurrence to the sorted list. (`Minus` filters out all matches, so we have to explicitly push the duplicates.)

```
Ｅυ⭆ι§ηλ

```

Restore each integer array to its original string and output each string on its own line.

# Answer
> 0 votes
# 05AB1E, 26 bytes

```
Σε•ª¯æ·$ÎÐ+MAî+X•4Bžnø{Ssk

```

Try it online! Beats all other answers.

```
Σε•...•4Bžnø{Ssk  # trimmed program
                  # implicit input...
Σ                 # sorted by...
              sk  # index of...
                  # (implicit) current element in...
 ε                # map over letters of...
                  # (implicit) current element in sort...
              sk  # in...
                  # (implicit) flat...
             S    # list of characters in...
                  # (implicit) each element of...
            {     # sorted list of...
                  # (implicit) all elements of...
  •...•           # 12827082404216683880457031718358...
        B         # in base...
       4          # literal...
           ø      # with each element paired with corresponding element from...
         žn       # "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
                  # implicit output

```

---
Tags: code-golf, sorting, alphabet
---


title: Implement ΔList

text:
# Question
Title: Implement ΔList
Given a list of integers, such as `{1, 4, 2, 8, 10}`, TI-Basic's `ΔList` will determine the difference between every overlapping pair of items. In the given example, it would be `{3, -2, 6, 2}`.

**Task:**

Take a list of integers as input, in any reasonable way. All overlapping pairs `{x, y}` should become `y - x`, and the resulting list returned. It should always be one item shorter. You can assume the list will never be shorter than two items.

**Test cases:**

```
{1, 2}                  {1}
{1, 2, 4}               {1, 2}
{2, 1}                  {-1}
{2, 2, 2}               {0, 0}
{-1, 0, 0, -1}          {1, 0, -1}
{0, 1, 2, 1, 1, 0}      {1, 1, -1, 0, -1}

```

**Other:**

This is . Shortest answer (in bytes) per language wins!

# Answer
> 6 votes
# V (vim), <sup>~~33 26~~</sup> 25 bytes

```
qqjYkPJr-0C<c-r>=<c-r>"
<Esc>j@qq@qdd

```

Try it online!

Input as a newline separated list of integers.

-7 bytes from kops.

-1 more byte from kops.

## Explanation

```
qqjYpkk:s/\n/-
qq             start macro q
  jYp          go down and duplicate the second line from the cursor
     kk        move back to the original position
       :s/\n/- replace newline with -
               Current Line: n1-n2

C<c-r>=-(<c-r>")
C                cut current line, enter insert mode
 <c-r>=          evaluate the following
       -(<c-r>") negate n1-n2

<Esc>j@qq@qdd
<Esc>         exit insert mode
     j        go 1 step down to the next values
      @qq     recursively call macro q and end macro
         @q   call macro q
           dd delete last extra line

```

# Answer
> 4 votes
# Trivial answers

# 05AB1E, 1 byte

```
¥

```

Try it online!

# , 4 bytes

```
diff

```

Try it online!

# Jelly, 1 byte

```
I

```

Try it online!

Feel free to add your answers here.

# Answer
> 4 votes
# Retina 0.8.2, 82 bytes

```
\d+
$*
¶.*
$&-$%`
^.*¶

%(`^((-1+)|(1*)-)-(1*)$
$2$3$4
(1*)-+\1
-
--|-$

1`1*$
$.&

```

Try it online! Takes input on separate lines but test suite converts from and to comma delimited for convenience. Explanation:

```
\d+
$*

```

Convert to unary.

```
¶.*
$&-$%`

```

Create expressions for the differences of successive terms. `$%`` grabs the previous term without having to match it.

```
^.*¶

```

Delete the first term.

```
%(`

```

Perform the rest of the script individually on each subtraction.

```
^((-1+)|(1*)-)-(1*)$
$2$3$4

```

If the two values have different signs then negate the second and add it to the first.

```
(1*)-+\1
-

```

Otherwise subtract the two values.

```
--|-$

```

The subtraction can result in a double negative or a trailing subtraction of zero which needs to be removed.

```
1`1*$
$.&

```

Convert to decimal.

# Answer
> 3 votes
# JavaScript (ES6), 32 bytes

```
a=>a.slice(1).map((v,i)=>v-a[i])

```

Try it online!

---

### JavaScript (ES6), 33 bytes

```
a=>a.map(v=>-p+(p=v),p=a.shift())

```

Try it online!

### JavaScript (ES10), 34 bytes

```
a=>a.flatMap((v,i)=>i?v-a[i-1]:[])

```

Try it online!

# Answer
> 3 votes
# APL 5 bytes

```
2-⍨/⎕

    ⎕ ⍝ input
 -⍨   ⍝ reversed subtraction
2  /  ⍝ between every 2 elements like [1,2,3] -> [1 f 2, 2 f 3]

```

try it online

# Answer
> 3 votes
# Python 3, 38 bytes

```
lambda s:[y-x for x,y in zip(s,s[1:])]

```

Try it online!

-8 bytes thanks to @cairdcoinheringaahing

# Answer
> 2 votes
# Charcoal, 10 bytes

```
ＩＥΦθκ⁻ι§θκ

```

Try it online! Link is to verbose version of code. Explanation:

```
   θ        Input array
  Φ         Filtered where
    κ       Current index is not zero
 Ｅ          Map over remaining elements
      ι     Current element
     ⁻      Subtract
        θ   Input array (still with zeroth element)
       §    Indexed by
         κ  Current index
Ｉ           Cast to string
            Implicitly print

```

# Answer
> 1 votes
# Haskell, 17 bytes

```
zipWith(-)=<<tail

```

Try it online!

# Answer
> 1 votes
# Jelly, 2 bytes

Try it online!

Full program, as it relies on Jelly's outputting format.

This applies `I` (forward differences) to each overlapping pair `[x, y]` (`Ɲ`), yielding `[y - x]` for each. Due to Jelly's printing, as a full program, it omits the brackets around single element lists, so the output looks like a flat list.

# Jelly, 3 bytes

Non-builtin approaches. All are functions

```
_ƝN

```

Try it online!

```
_@Ɲ

```

Try it online!

```
IƝF

```

Try it online!

## How they work

They all use the `Ɲ` quick, which takes a link before it (a command, usually an atom) and a list, and applies the link to all overlapping pairs in the list.

`_` is subtraction in Jelly, and `@` reverses the order of the arguments to the previous link.

The first one calculates `x - y` for each overlapping pair, then negates each.

The second calculates `x -@ y` for each overlapping pair, which is equivalent to `y - x`

The third applies `I` (forward differences) to each pair, yielding `[y - x]`. We then flatten this into a single array.

# Answer
> 1 votes
# , 25 bytes

```
head((x=scan())[-1]-x,-1)

```

Try it online!

The  'trivial' answer is `diff` (difference).

So this is my attempt at the golfiest solution *without* diff...

# Answer
> 0 votes
# Wolfram Language (Mathematica), 11 bytes

```
Differences

```

Try it online!

---
Tags: code-golf, math, array, arithmetic
---


title: Help me count the Omer

text:
# Question
Title: Help me count the Omer
During the 49 days between Passover and Pentecost, Jewish liturgy provides four numerical problems that I've here phrased as code golf problems.

## Input/Arguments

These four, in any order, and by any means:

* A text \\$L\\$ consisting of exactly 7 sentences.
    + The first and last sentences have 7 words each, the middle one has 11 words, and the remaining four have 6 words each.
    + The 11-word sentence has 49 letters in total.
    + The sentences may have commas, and they all have a trailing period.
    + You can take this as a 7-element list of strings or as a single string with spaces or line breaks after the inner periods, and optionally after the last one as well.
* A text \\$A\\$ consisting of 7 sentences.
    + Each sentence has exactly 6 words.
    + The sentences may have commas, and they all have a trailing period.
    + You can take this as a 7-element list of strings or as a single string with spaces or line breaks after the inner periods, and optionally after the last one as well.
* A list \\$S\\$ consisting of exactly 7 words.
    + These are all-lowercase.
    + These have no punctuation.
* An integer \\$N\\$ in the inclusive range 1 though 49.
    + You are **not** allowed to substitute with 0 through 48.

Alternatively, you can use \\$L\\$, \\$A\\$, and \\$S\\$ as predefined variables, and only take \\$N\\$.

## Output/Results

These four, in this precise order, though in any reasonable format, including with extra trailing whitespace:

1. The text “\\$N\\$ `days, namely` \\$N\_1\\$ `weeks` \\$N\_0\\$ `days`”, where \\$(N\_1,N\_0)\_7\\$ is \\$N\\$ in base seven, except for \\$N=49\\$ where \\$N\_1=7\\$ and \\$N\_0=0\\$.

* You must omit the plural “`s`” after any number that is \\$1\\$.
    * You must omit any part that is \\$0\\$.
    * You must omit the second phrase (from and including the comma) if \\$N≤6\\$.
    * Examples:
        + \\$N=1\\$: “`1 day`
        + \\$N=6\\$: “`6 days`
        + \\$N=7\\$: “`7 days, namely 1 week`
        + \\$N=8\\$: “`8 days, namely 1 week 1 day`
        + \\$N=13\\$: “`13 days, namely 1 week 6 days`
        + \\$N=14\\$: “`14 days, namely 2 weeks`
        + \\$N=15\\$: “`15 days, namely 2 weeks 1 day`
2. The text of \\$L\\$ but with the \\$N\\$th word highlighted, and the \\$N\\$th letter of the middle sentence highlighted.

* The highlightings must consist of two distinct enclosures of your choice.
    * The enclosing characters must not be letters, nor space, comma, or period. All other visible characters are allowed.
    * For example, you can enclose the word in square brackets (“`[word]`”) and the letter in curly braces (“`l{e}tter`”), or you could enclose the word in double-asterisks (“`**word**`”) and the letter in single-asterisks (“`l*e*tter`”).
    * Spaces, commas, and periods must not be highlighted.
    * Be aware that there will be a value of \\$N\\$ for which the highlighted letter will appear inside the highlighted word (“`[co{m}bo]`” or (“`**co*m*bo**`” etc.).
3. The text of \\$A\\$ but with one word or sentence highlighted.

* If \\$N=1\\$ then highlight the first word.
    * Otherwise, if \\$N\\$ is evenly divisible by \\$7\\$ then highlight the entire \\$N\over7\\$th sentence.
    * Otherwise, highlight the word that follows immediately after the highlighting done for \\$N-1\\$.
    * Commas and periods must not be highlighted when highlighting a word.
    * For example, for \\$N=8\\$, highlight the first word of the second sentence.
4. The text “\\$S\_0\\$ `in` \\$S\_1\\$”, where \\$S\_0\\$ is the \\$(M\_0+1)\\$th word of \\$S\\$ and \\$S\_1\\$ is the \\$(M\_1+1)\\$th word of \\$S\\$, and \\$M=N-1\\$.

* For example, for \\$N=8\\$, \\$M=N-1=7\\$ which is \\$(1,0)\_7\\$, and therefore \\$S\_0\\$ is the second word of \\$S\\$ and \\$S\_1\\$ is the first word of \\$S\\$.
    * The trailing period must also be highlighted when highlighting a sentence.

## Examples

For these examples, `[``]` is used to highlight words and sentences, `{``}` is used to highlight letters, and \\$L\\$ is:

```
God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk sing joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

\\$A\\$ is:

```
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

\\$S\\$ is:

```
kindness
might
beauty
victory
glory
groundedness
royalty

```

### For \\$N=1\\$

`1 day`

```
[God] bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
{F}olk sing joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
[Power] please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`kindness in kindness`

### For \\$N=6\\$

`6 days`

```
God bless grace, face shine [us] forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk s{i}ng joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
Power please, great right, release [captive].
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`groundedness in kindness`

### For \\$N=7\\$

`7 days, namely 1 week`

```
God bless grace, face shine us [forever].
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk si{n}g joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
[Power please, great right, release captive.]
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`royalty in kindness`

### For \\$N=8\\$

`8 days, namely 1 week 1 day`

```
God bless grace, face shine us forever.
[Know] earth ways, saves all nations.
Praise people Lord, all people praise.
Folk si{n}g joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
Power please, great right, release captive.
[Accept] prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`kindness in might`

### For \\$N=13\\$

`13 days, namely 1 week 6 days`

```
God bless grace, face shine us forever.
Know earth ways, saves all [nations].
Praise people Lord, all people praise.
Folk sing joy, f{o}r judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome [purify].
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`groundedness in might`

### For \\$N=14\\$

`14 days, namely 2 weeks`

```
God bless grace, face shine us forever.
Know earth ways, saves all nations.
[Praise] people Lord, all people praise.
Folk sing joy, fo{r} judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
Power please, great right, release captive.
[Accept prayer, strengthen people, Awesome purify.]
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`royalty in might`

### For \\$N=15\\$

`15 days, namely 2 weeks 1 day`

```
God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise [people] Lord, all people praise.
Folk sing joy, for {j}udges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
[Please] Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`kindness in beauty`

### For \\$N=25\\$

`25 days, namely 3 weeks 4 days`

```
God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk sing joy, for judges [peop{l}e] justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

```

```
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous [mercy], bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

```

`victory in victory`

### For \\$N=49\\$

`49 days, namely 7 weeks`

```
God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk sing joy, for judges people justly, guide earth folk eve{r}.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth [ends].

```

```
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
[Accept supplication, hear cry, thoughts knower.]

```

`royalty in royalty`

# Answer
# Python 3, 365 bytes

```
import re
i=N=int(input())
p=print
Y=N//7
Z=N%7
p(N,"day"+"s"*(N>1)+(f", namely {Y} week{'s'*(N>13)}"+f" {Z} day{'s'*(Z>1)}"*(Z>0))*(N>6))
s="[]"
def a(x):global i;i-=1;x=x.group();return i and x or x.join(s)
b=re.sub
L=b("\w+",a,L).split("\n")
if Z:i=N-Y;A=b("\w+",a,A)
else:i=Y;A=b(".+",a,A)
s="{}"
i=N
L[3]=b("\w",a,L[3])
[*map(p,L)]
p(A)
p(S[~-N%7],"in",S[~-Y])

```

Try it online!

-27 bytes thanks to RootTwo
-6 bytes thanks to ovs

Accepts \\$L,A,S\\$ as pre-defined variables. These definitions are in the header, but I am reading from STDIN just to make testing easier.
> 5 votes

# Answer
# Retina 0.8.2, 323 bytes

```
^.+
$*
^(1(1{7})*(1)*[\w\W]*¶¶)(?=(?<-3>.+¶)*(.+))(?<-2>.+¶)*(.+)(¶.+)*
$1$4 in $5
^((1{7})*(1)?(1)*¶(¶.+)+¶(?<-2>.*¶)*)(?(3)(.*¶(?<-4>\w+\W+)*)(\w+)|(.+))
$1$6<$7$8>
^(1(1)*¶¶(?<-2>\w+\W+)*)(\w+)
$1<$3>
^(1(1)*¶¶(.+¶){3}<?(?<-2>\w\W*)*)(\w)
$1{$4}
^(1{7})*(1)*
$.& days, namely $#1 weeks $#2 days
(,.*y)? 0.*|\b(1 \w+)s
$2

```

Try it online! Takes N, L, A and S as input, double-spaced from each other. Explanation:

```
^.+
$*

```

Convert `N` to unary.

```
^(1(1{7})*(1)*[\w\W]*¶¶)(?=(?<-3>.+¶)*(.+))(?<-2>.+¶)*(.+)(¶.+)*
$1$4 in $5

```

Divmod `N-1` by `7`, capturing the appropriate words from `S` and replacing `S` with the desired phrase.

```
^((1{7})*(1)?(1)*¶(¶.+)+¶(?<-2>.*¶)*)(?(3)(.*¶(?<-4>\w+\W+)*)(\w+)|(.+))
$1$6<$7$8>

```

Divmod `N` by `7`. If the remainder was zero, then capture the `N/7`th line of A, otherwise capture the `N%7-1`th word on the following line. Surround it with `<>`s.

```
^(1(1)*¶¶(?<-2>\w+\W+)*)(\w+)
$1<$3>

```

Capture the `N`th word of `L` and surround it with `<>`s.

```
^(1(1)*¶¶(.+¶){3}<?(?<-2>\w\W*)*)(\w)
$1{$4}

```

Capture the `N`th letter of the middle line of `L` and surround it with `{}`s.

```
^(1{7})*(1)*
$.& days, namely $#1 weeks $#2 days

```

Divmod `N` by `7` again. Convert `N` back to decimal, as well as `N/7` and `N%7`, as the desired phrase, assuming all values exceed `1`.

```
(,.*y)? 0.*|\b(1 \w+)s
$2

```

Fix up `0` and `1` values.
> 3 votes

# Answer
# JavaScript (Node.js), ~~539...~~  431 bytes

```
(L,A,S,N,B=N%7,J=N/7,u=D=>D>1?'s':'',z=/[. ,]/,g=w=>`[${w.replace(z,'')}]${z.test(w)?w.slice(-1):''}`)=>[N+` day${u(N)}${N>6?`, namely ${H=J|0} week${u(H)} ${B?B+` day`+u(B):''}`:''}`,(t=0)||(L[3]=L[3].replace(/[a-zA-Z]/g,c=>++t==N?`{${c}}`:c))&&L.join` `.split` `.map((e,i)=>i==N-1?g(e):e).join` `,A.map((e,i)=>N%7?i==~~J?((E=e.split` `)[--B]=g(E[B]))&&E.join` `:e:i==J-1?`[${e}]`:e).join`
`,S[N%7?B:6]+' in '+S[N<8?0:N>48?6:J|0]]

```

Try it online!

This is long. Like REALLY long.

Takes `L`, `A` and `S` as arrays of strings.

I also love how the code breaks the syntax highlighter.

## How does it work?

Declares a huge amount of default arguments to save on bytes, as many of these arguments are referred to later. The first four arguments are simply the texts.

`B` and `J` are simply values derived from N which are used extensively in the code.

`u` is a helper function which returns an `s` depending on the value of the input.

`z` is simply a regular expression characterized by a single character class containing all forbidden characters for highlighting: space, period and comma.

`g` is a helper function called twice which highlights a word without forbidden characters being caught up in the word.

In the function body, we return an array of four strings:

* using rudimentary ternaries, get the formatted "days" string.
* the `L`-string. Procedure: first, replace the fourth sentence with the same sentence but with one letter highlighted. Then do the word highlighting using the `g` function.
* the `A`-string. Frankly, even I can't read my own code, but essentially highlights one word or one sentence. Can't go into detail on this one.
* the `S`-string. A bunch of simple ternaries based on the value of `N`.
> 1 votes

---
Tags: code-golf, string, sequence, base-conversion, generation
---


title: Convert superscripts to MathJax

text:
# Question
Title: Convert superscripts to MathJax
CGCC hasn't always had MathJax. Back in the dark ages, it would have been necessary to write \\$x^2\\$ as  (the horror!). In this challenge, you will be given some math which may include superscripts, and you should convert it to MathJax.

**Input:**

Input will consist of one or more letters `a` to `z`, some with superscripts. Answers may choose to handle only upper or lower case, or both.

Examples of inputs would be `x`, , `xy²`, `x²y²`, or `x²yz`. There will never be duplicates of a letter (so `xx` or `x²zx` won't be given), but you cannot assume the superscripts or letters are in any particular order. The first character in the input will never be a superscript.

Superscripts consist of the characters `¹`, `²`, `³`, , , , , , , and . These can be joined into multi-digit superscripts, like x²¹ (\\$x^{21}\\$). You can assume  or `¹` are never given as superscripts, and there will not be leading s.

**Output:**

Output should consist of a MathJax representation of the input. This must start and finish with `\$`.

Characters without superscripts can be written as themselves; `xyz` would simply become `\$xyz\$`. Characters with superscripts should be followed by `^`, then the superscript written with normal digits and wrapped in `{}`. For example, `x²¹z⁴⁸⁸` would become `\$x^{21}z^{488}\$`. Optionally, single digit superscripts can be written without the `{}`. For example,  could be either `\$x^{2}\$` or `\$x^2\$`.

**Test cases:**

```
x           \$x\$
xyz         \$xyz\$
x²          \$x^{2}\$ OR \$x^2\$
x²¹         \$x^{21}\$
x²yz²       \$x^{2}yz^{2}\$ OR \$x^2yz^2\$
xy¹¹z       \$xy^{11}z\$
x⁴          \$x^{4}\$ OR \$x^4\$
x⁶⁰         \$x^{60}\$

```

**Other:**

This is , shortest answer (in bytes) per language wins!

# Answer
> 6 votes
# Husk, ~~43 41~~ 40 bytes

```
`JD;"¦$"ṁ?Iȯ:'^`J"{}"ṁos€"¹²³⁴⁵⁶⁷⁸⁹"Λ√ġ√

```

Try it online!

The superscripts are 1 byte each since they're in Husk's codepage.

I wanted to replace `+₁+₁` with `S+`+"¦$"` but it didn't work for some reason.. :(

-2 bytes borrowing the indexing idea from hyper-neutrino.

-1 byte from Leo.

## Explanation

```
`JD;"¦$"ṁ?Iȯ`:'}+"^{"ṁos€"¹..⁹"Λ√ġ√
                              ġ√ group on alphabets
     ṁ                           map and concatenate with:
      ?                            if:
                            Λ√      the group is alphabetical
       I                             leave as is
        ȯ`:'}+"^{"ṁos€"¹..⁹"        otherwise:
                  ṁȯ                  map and concat each char to:
                     €"¹..⁹"           index in ¹..⁹(0 if not present)
                    s                  cast to string
             +"^{"                    prepend "^{"
         `:'}                         append '{'
`JD;"¦$"                            surround the final string with "\$"

```

# Answer
> 6 votes
# JavaScript, 55 bytes

```
e=>`\\$${e.normalize`NFKD`.replace(/\d+/g,`^{$&}`)}\\$`

```

Try it online!

# Answer
> 5 votes
# Factor, ~~148~~ ~~92~~ ~~77~~ 70 bytes

```
[ nfkd R/ \d+/ [ "^{""}"surround ] re-replace-with "\\$%s\\$"sprintf ]

```

It doesn't work on TIO because TIO is missing `nfkd` which is perfectly extant in a proper copy of 0.98. So have a screenshot of running the quotation in the listener.

## Explanation:

It's a quotation (anonymous function) that takes a string from the data stack as input and leaves a string on the data stack as output.

* `nfkd` Convert a string to normalization form KD. (Turn `"²"` into `"2"`, for example.)
* `R/ \d+/` A regular expression that matches numbers.
* `[ "^{""}"surround ] re-replace-with` Replace numbers with themselves surrounded by `^{...}`.
* `"\\$%s\\$"sprintf` Surround the result with `\\$`.

# Answer
> 4 votes
# Brachylog, ~~65~~ 59 bytes

```
~c{{∧"⁰¹²³⁴⁵⁶⁷⁸⁹"},?XdX&|{~h.↰₂i}ᵐtᵐcṫ,"}^{"↻↻}ᵐ{,"\$"↔}ⁱ²c

```

Try it online!

:/

# Answer
> 3 votes
# Jelly, 38 bytes

```
ØJiⱮ_81»48Ọ⁾^{;;”}
O>Ø⁷Œgṁ@µ¹Çƭ€⁾\$,ṁ3

```

Try it online!

-4 bytes thanks to Jonathan Allan ("subtract 81, max with 48" is shorter than "logical OR 129, subtract 81") (prepend `\$` and mold like 3 is shorter than prepend `\$` \+ append `\$`) (2-byte built-in for 128 saves a byte)

Unfortunately I can't generate a test suite for this because `tie` will keep cycling, which causes various issues.

Might add explanation later after golfing (if I do either). TL;DR, groups by superscripts and non-superscripts, the applies the last link to every other element using tie-each, and the last link indexes into jelly's codepage, which contains ^1 through ^9, uses `or` to fix the lack of ^0 (absent items have index 0 since jelly is 1-indexed), subtract the offset, turn back to `chr`, and then apply formatting

# Answer
> 3 votes
# Ruby, ~~67~~ 61 bytes

```
->s{'\$'+s.unicode_normalize(:nfkd).gsub(/\d+/,'^{\0}')+'\$'}

```

Try it online!

`unicode_normalize(:nfkd)` seems quite long, but turns out to be 4 bytes shorter than `tr('⁰¹²³⁴-⁹','0-9')`.

# Answer
> 3 votes
# JavaScript (Node.js), ~~92~~ 89 bytes given that no constant(\\$2x^3\\$)

```
x=>`\\$${[...x].map(c=>c=='¹'?1:escape(c).slice(-1)).join``.replace(/\d+/g,'^{$&}')}\\$`

```

Try it online!

# JavaScript (Node.js), ~~99~~ 94 bytes

```
x=>`\\$${x.replace(/[~-⁹]+/g,s=>`^{${[...s].map(c=>c=='¹'?1:escape(c+c)[5]).join``}}`)}\\$`

```

Try it online!

# ~~76~~ 71 bytes if allowed

```
x=>`\\$${x.replace(/[~-⁹]/g,c=>`{}^${c=='¹'?1:escape(c+c)[5]}`)}\\$`

```

Try it online!

# Answer
> 3 votes
# Raku, 35 bytes

```
{'\$'~S:g/\d+/^\{$/}/~'\$'}o~*.NFKD

```

Try it online!

This expression is the composition of two functions with the `o` operator. The right-hand function (the first to be applied) is `~*.NFKD`, which calls the `NFKD` method on its argument, then stringifies it, which turns superscript numbers into regular numbers. The left-hand function (between the brackets) constructs the final string by prepending and appending `\$` and using a regex to replace sequences of consecutive digits with `^{digits}`.

# Answer
> 2 votes
# Python 3, 169 bytes

```
def k(s):
 g="¹²³⁴⁵⁶⁷⁸⁹⁰";h="\$"
 for y,x in enumerate(s):
  if s[y]in g:h+='^{'+x;continue
  if(x not in g)and(s[y-1]in g):h+='}'
  h+=x
 return h+'\$'

```

Try it online!

# Answer
> 2 votes
# Python 3, ~~245~~ 241 bytes

```
def m(a):
	b='⁰¹²³⁴⁵⁶⁷⁸⁹';r=c=0;o='\\$'
	for l in a:
		if l in b:
			n=str(b.index(l))
			if not r:o+='^{'+n;r=1
			elif r:o+=n
			if c==len(a)-1:o+='}'
		elif l not in b and r:o+='}'+l;r=0
		else:o+=l
		c+=1
	return o+'\\$'

```

Try it online! -4 bytes thanks to pxeger.

# Answer
> 2 votes
# Red, 170 bytes

```
func[a][s: charset extract t:"⁰0¹1²2³3⁴4⁵5⁶6⁷7⁸8⁹9"2
parse a[any[any[not s skip]ahead s insert"^^{"any[change
set c s(t/:c)]insert"}"]]rejoin["\$"a"\$"]]

```

Try it online!

# Answer
> 2 votes
# Charcoal, 29 bytes

```
\$Ｆ⁺Ｓ\$¿›ιz⊞υＶι«∧υ⪫{}⪫υωι≔⟦⟧υ

```

Try it online! Link is to verbose version of code. Explanation:

```
\$

```

Print the leading MathJax tag.

```
Ｆ⁺Ｓ\$

```

Append the trailing MathJax tag to the input string. This ensures that a subscript is not the last character in the loop.

```
¿›ιz

```

If the current character is greater than a `z`, then...

```
⊞υＶι

```

... evaluate it as a Charcoal digit and push the result to the predefined empty list.

```
«

```

Otherwise,

```
∧υ⪫{}⪫υω

```

If there is a superscript to print, then join the digits together and wrap them in `{}`s.

```
ι

```

Output the next character.

```
≔⟦⟧υ

```

Clear any superscript.

# Answer
> 2 votes
# Retina 0.8.2, 36 bytes

```
T`⁰¹²³⁴-⁹`d
\d+
{$&}
^|$
\$

```

Try it online! Link includes test cases. Explanation:

```
T`⁰¹²³⁴-⁹`d

```

Convert the superscripts to digits. (The `¹²³` cost 2 bytes each and the `⁰⁴⁹` cost three bytes each.)

```
\d+
{$&}

```

Wrap the superscripts in `{}`s.

```
^|$
\$

```

Wrap the entire string in MathJax tags.

# Answer
> 2 votes
# PHP, ~~75~~ 73 bytes

```
fn($a)=>preg_replace('/\d+/','^{$0}',normalizer_normalize("\\$$a\\$",8));

```

https://3v4l.org/mJZKd

Works with PHP 7.4+ with the intl extension, doesn't work on TIO.

8 is the value of the `Normalizer::FORM_KD` constant, so this converts superscript characters to digits using NFKD.

# Answer
> 2 votes
# Zsh `--extendedglob`, ~~121 116~~ 67 bytes

*Saved **a lot** by enabling extendedglob for the `(#m)` and `##` glob specs.*

```
<<<${1//(#m)[^a-z]##/^\{${MATCH//(#m)?/$[c=#MATCH,c-185?c&15:1]}\}}

```

~~Try it online (has old comments)~~  Try it online!

```
${1//$find/$repl}  # replace all instances of $find with $repl
[^a-z]##           # The glob [^a-z]## is equivalent to the regex [^a-z]+
(#m)[^a-z]##       # Set $MATCH to the value matched by [^a-z]]##
(#m)?              # "?" matches any single character
$[$e1,...,$en]     # $[arithmetic substitution], substitutes the result of $en
c=#MATCH           # Set c to the codepoint of the first character of $MATCH
c&15               # ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁰ => #c & 15 => 9 1 2 3 4 5 6 7 8 9 0
c-185?c&15:1       # If $MATCH is ¹ (codepoint 185), output 1, else codepoint & 15
<<<$str            # prints $str to stdout

```

# Answer
> 1 votes
# JavaScript (Node.js), 60 bytes

```
s=>`\\$${s.replace(/\W+/g,n=>`^{${n.normalize`NFKD`}}`)}\\$`

```

Try it online!

# Answer
> 0 votes
# 05AB1E, 34 bytes

```
"⁰¹²³⁴⁵⁶⁷⁸⁹"S9Ý€"^{ÿ}":„\$.ø…}^{õ:

```

Try it online!

## Explained:

```
"..."S                        # Push [⁰...⁹]
      9Ý                      # Push [0...9]
        €"^{ÿ}"               # Surround each element of [0...9] with ^{ }
               :              # Replace each element of [⁰...⁹] with its counterpart in [^{0}...^{9}]
                   .ø         # Surround input with...
                „\$           # \$ \$
                          :   # Replace...
                     …}^{     # instances of  "}^{"
                         õ    # with an empty string

```

---
Tags: code-golf, string, math
---