git add d21p2.swift
This commit is contained in:
@@ -56,8 +56,17 @@ struct Dirpad : Pad {
|
|||||||
nL: (1, 0), nD: (1, 1), nR: (1, 2)
|
nL: (1, 0), nD: (1, 1), nR: (1, 2)
|
||||||
]
|
]
|
||||||
static var cache: [KeyPair: Set<[Key]>] = [
|
static var cache: [KeyPair: Set<[Key]>] = [
|
||||||
// >^ >A >< >v (>>)
|
// <<0 <v- <>- <^. <A.
|
||||||
// v< v> v^ vA? (vv)
|
// v<- vv0 v>- v^- vA
|
||||||
|
// ><- >v- >>0 >^ >A-
|
||||||
|
// ^<. ^v- ^> ^^0 ^A-
|
||||||
|
// A<. Av A>- A^- AA0
|
||||||
|
// Noops
|
||||||
|
KeyPair(a: nL, b: nL): [[]],
|
||||||
|
KeyPair(a: nR, b: nR): [[]],
|
||||||
|
KeyPair(a: nU, b: nU): [[]],
|
||||||
|
KeyPair(a: nD, b: nD): [[]],
|
||||||
|
KeyPair(a: nA, b: nA): [[]],
|
||||||
// Only solutions due to gap
|
// Only solutions due to gap
|
||||||
KeyPair(a: nL, b: nU): [[nR, nU]],
|
KeyPair(a: nL, b: nU): [[nR, nU]],
|
||||||
KeyPair(a: nL, b: nA): [[nR, nR, nU]],
|
KeyPair(a: nL, b: nA): [[nR, nR, nU]],
|
||||||
@@ -76,8 +85,9 @@ struct Dirpad : Pad {
|
|||||||
KeyPair(a: nR, b: nA): [[nU]],
|
KeyPair(a: nR, b: nA): [[nU]],
|
||||||
KeyPair(a: nU, b: nD): [[nD]],
|
KeyPair(a: nU, b: nD): [[nD]],
|
||||||
KeyPair(a: nD, b: nU): [[nU]],
|
KeyPair(a: nD, b: nU): [[nU]],
|
||||||
// Known short ones
|
// Known short ones. TODO: proper DP this part instead of by hand
|
||||||
KeyPair(a: nA, b: nD): [[nL, nD]],
|
KeyPair(a: nA, b: nD): [[nL, nD]],
|
||||||
|
KeyPair(a: nD, b: nA): [[nU, nR]],
|
||||||
KeyPair(a: nR, b: nU): [[nL, nU]],
|
KeyPair(a: nR, b: nU): [[nL, nU]],
|
||||||
KeyPair(a: nU, b: nR): [[nD, nR]]
|
KeyPair(a: nU, b: nR): [[nD, nR]]
|
||||||
]
|
]
|
||||||
@@ -143,22 +153,25 @@ Dirpad.press(nA, "v<<AA>^AA>A".map(String.init)[...])
|
|||||||
|
|
||||||
//let answer = try readInput(CommandLine.arguments[1]).map { passwd in
|
//let answer = try readInput(CommandLine.arguments[1]).map { passwd in
|
||||||
// Numpad.press(nA, passwd[...]).flatMap { dirSeq1 in
|
// Numpad.press(nA, passwd[...]).flatMap { dirSeq1 in
|
||||||
let _ = [[">", "A"]].map { passwd in
|
let _ = [["v", "A"]].map { passwd in
|
||||||
Dirpad.press(nA, passwd[...]).flatMap { dirSeq1 in
|
Dirpad.press(nA, passwd[...]).forEach { dirSeq1 in
|
||||||
Dirpad.press(nA, dirSeq1[...]).flatMap { dirSeq2 in
|
Dirpad.press(nA, dirSeq1[...]).forEach { dirSeq2 in
|
||||||
Dirpad.press(nA, dirSeq2[...]).flatMap { dirSeq3 in
|
Dirpad.press(nA, dirSeq2[...]).forEach { dirSeq3 in
|
||||||
Dirpad.press(nA, dirSeq3[...]).flatMap { dirSeq4 in
|
Dirpad.press(nA, dirSeq3[...]).forEach { dirSeq4 in
|
||||||
Dirpad.press(nA, dirSeq4[...]).flatMap { dirSeq5 in
|
Dirpad.press(nA, dirSeq4[...]).forEach { dirSeq5 in
|
||||||
|
//Dirpad.press(nA, dirSeq4[...]).forEach { dirSeq6 in
|
||||||
let out: String = (
|
let out: String = (
|
||||||
"\(passwd.joined()) " +
|
"\(passwd.joined()) " +
|
||||||
"\(dirSeq1.joined()) " +
|
"\(dirSeq1.joined()) " +
|
||||||
"\(dirSeq2.joined()) " +
|
"\(dirSeq2.joined()) " +
|
||||||
"\(dirSeq3.joined()) " +
|
"\(dirSeq3.joined()) " +
|
||||||
"\(dirSeq4.joined()) " +
|
"\(dirSeq4.joined()) " +
|
||||||
"\(dirSeq5.joined()) " +
|
"\(dirSeq5.count) " +
|
||||||
""
|
// "\(dirSeq6.count) " +
|
||||||
)
|
""
|
||||||
print(out.replacingOccurrences(of: "A", with: "|"))
|
).replacingOccurrences(of: "A", with: "|")
|
||||||
|
print("\(dirSeq5.count)" + out)
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,21 +179,20 @@ let _ = [[">", "A"]].map { passwd in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var answer = 0
|
var answer = 0
|
||||||
for passwd in try readInput(CommandLine.arguments[1]) {
|
for passwd in try readInput(CommandLine.arguments[1]) {
|
||||||
var seq = Numpad.press(nA, passwd[...])
|
var seq = Numpad.press(nA, passwd[...])
|
||||||
seq.map { $0.joined() }.forEach { print("\($0.count): \($0)") }
|
seq.map { $0.joined() }.forEach { print("\($0.count): \($0)") }
|
||||||
print()
|
print()
|
||||||
for _ in 0..<2 {
|
for _ in 0..<25 {
|
||||||
let tmpSeq = seq.flatMap { seq in Dirpad.press(nA, seq[...]) }
|
let tmpSeq = seq.flatMap { seq in Dirpad.press(nA, seq[...]) }
|
||||||
let minLen = seq.map { $0.count }.min()!
|
let minLen = seq.map { $0.count }.min()!
|
||||||
seq = tmpSeq.filter { $0.count > minLen }
|
seq = tmpSeq.filter { $0.count > minLen }
|
||||||
seq.map { $0.joined() }.forEach { print("\($0.count): \($0)") }
|
//seq.map { $0.joined() }.forEach { print("\($0.count): \($0)") }
|
||||||
print()
|
//print()
|
||||||
}
|
}
|
||||||
let r = seq.map { $0.count }.min()! * Int(passwd.joined().dropLast())!
|
let r = seq.map { $0.count }.min()! * Int(passwd.joined().dropLast())!
|
||||||
print("\(passwd.joined()): \(r)")
|
//print("\(passwd.joined()): \(r)")
|
||||||
answer += r
|
answer += r
|
||||||
}
|
}
|
||||||
print(answer)
|
print(answer)
|
||||||
|
Reference in New Issue
Block a user