I am 7 stars short for whatever pt 2 is... I'm EXTREMELY tempted to just run other people's code on my inputs, so I can know...
I am somewhat fascinated by how simple yet troublesome this problem was!!
Converting out of SNAFU digits wasn't a big deal, my switch required a line of code for each one, so many small dances were performed...
while !editableString.isEmpty {
let digit = editableString.removeLast()
switch digit {
case "2":
total += 2 * multiplier
case "1":
total += multiplier
case "0":
print("do a little dance")
case "-":
total += -1 * multiplier
case "=":
total += -2 * multiplier
default:
assertionFailure("what crazy digit bullshit is this?")
}
multiplier *= 5
}
...but the reverse was a bit of a pain in the bitrot.
I ended up converting to base-5 first, and THEN rotating/carrying digits as I went, as needed. Doing both at once was Too Much for my tiny little brain ;)
the conversion from characterAtIndex, to Int in swift is... irksome.
let digit = snafu[index]
let nextDigit = Int(String(digit))! + carryValue
requiring double-casting, first to a string (this should be implicit, IMO), THEN to an int.
I hope all your blenders of starfruits were full (I'm 7 short!)