nothe

She's a Nerd!

  • she/her

Knitter, sewist, Seattle Soccer Fan, occasional tech stuff, whatever else tickles my fancy. Cilantro is fine, but pickles are a waste of a perfectly good cucumber.
@nothe@notacult.social


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
    }
syntax highlighting by codehost

...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
syntax highlighting by codehost

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!)


You must log in to comment.