* fix(guide) add stubs and correct file path misspellings and pr… (#36528) * fix: corrected file path to match curriculum * fix: renamed to newer challenge name * fix: added solutions to articles from challenge files * fix: added missing .english to file name * fix: added missing title to guide article * fix: correct solution for guide article * fix: replaced stub with hint * fix: added space in Hint headers * fix: added solution to guide article * fix: added solution to guide article * test: replaced stub with hint and solution * fix: add Problem number: to title * fix: changed generatorexponential to correct name * fix: renamed knight's tour to knights-tour * fix: updated guide article
58 lines
1.1 KiB
Markdown
58 lines
1.1 KiB
Markdown
---
|
|
title: State name puzzle
|
|
---
|
|
# State name puzzle
|
|
|
|
---
|
|
## Solutions
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
```javascript
|
|
function solve(input) {
|
|
var orig = {};
|
|
input.forEach(function(e) {
|
|
orig[e.replace(/\s/g, "").toLowerCase()] = e;
|
|
})
|
|
|
|
input = Object.keys(orig)
|
|
var map = {};
|
|
for (var i = 0; i < input.length - 1; i++) {
|
|
var pair0 = input[i];
|
|
for (var j = i + 1; j < input.length; j++) {
|
|
|
|
var pair = [pair0, input[j]];
|
|
var s = pair0 + pair[1];
|
|
var key = s.split("").sort();
|
|
|
|
var val = map[key] ? map[key] : [];
|
|
val.push(pair);
|
|
map[key] = val;
|
|
}
|
|
}
|
|
|
|
var result = [];
|
|
Object.keys(map).forEach((key) => {
|
|
|
|
for (var i = 0; i < map[key].length - 1; i++) {
|
|
var a = map[key][i];
|
|
for (var j = i + 1; j < map[key].length; j++) {
|
|
var b = map[key][j];
|
|
|
|
if ((new Set([a[0], b[0], a[1], b[1]])).size < 4)
|
|
continue;
|
|
var from = [orig[a[0]], orig[a[1]]].sort()
|
|
var to = [orig[b[0]], orig[b[1]]].sort()
|
|
result.push({
|
|
from,
|
|
to
|
|
})
|
|
}
|
|
}
|
|
});
|
|
|
|
return result;
|
|
}
|
|
```
|
|
|
|
</details> |