|
| 1 | +package hole |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "math/rand" |
| 6 | + "strings" |
| 7 | +) |
| 8 | + |
| 9 | +var arrowMap = map[string][2]int8{ |
| 10 | + // U+2190 - U+2199 |
| 11 | + "←": {-1, 0}, "↑": {0, 1}, "→": {1, 0}, "↓": {0, -1}, "↔": {0, 0}, |
| 12 | + "↕": {0, 0}, "↖": {-1, 1}, "↗": {1, 1}, "↘": {1, -1}, "↙": {-1, -1}, |
| 13 | + |
| 14 | + // U+21B0 - U+21B3 |
| 15 | + "↰": {-1, 1}, "↱": {1, 1}, "↲": {-1, -1}, "↳": {1, -1}, |
| 16 | + |
| 17 | + // U+21D0 - U+21D9 |
| 18 | + "⇐": {-1, 0}, "⇑": {0, 1}, "⇒": {1, 0}, "⇓": {0, -1}, "⇔": {0, 0}, |
| 19 | + "⇕": {0, 0}, "⇖": {-1, 1}, "⇗": {1, 1}, "⇘": {1, -1}, "⇙": {-1, -1}, |
| 20 | + |
| 21 | + // U+21E6 - U+21E9 |
| 22 | + "⇦": {-1, 0}, "⇧": {0, 1}, "⇨": {1, 0}, "⇩": {0, -1}, |
| 23 | + |
| 24 | + // U+2940 - U+2941 |
| 25 | + "⥀": {0, 0}, "⥁": {0, 0}, |
| 26 | +} |
| 27 | + |
| 28 | +func arrows() ([]string, string) { |
| 29 | + args := make([]string, 0, 3*len(arrowMap)) |
| 30 | + pos := [2]int8{} |
| 31 | + |
| 32 | + // 1-3 of each arrow. |
| 33 | + for arrow := range arrowMap { |
| 34 | + for times := rand.Intn(3); times >= 0; times-- { |
| 35 | + args = append(args, arrow) |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + // Shuffle the args. |
| 40 | + rand.Shuffle(len(args), func(i, j int) { |
| 41 | + args[i], args[j] = args[j], args[i] |
| 42 | + }) |
| 43 | + |
| 44 | + // Calculate the outs from the args. |
| 45 | + outs := make([]string, len(args)) |
| 46 | + for i, arrow := range args { |
| 47 | + coord := arrowMap[arrow] |
| 48 | + pos[0] += coord[0] |
| 49 | + pos[1] += coord[1] |
| 50 | + |
| 51 | + outs[i] = fmt.Sprintf("%d %d", pos[0], pos[1]) |
| 52 | + } |
| 53 | + |
| 54 | + return args, strings.Join(outs, "\n") |
| 55 | +} |
0 commit comments