Smash The Code - impossible with Swift

For an unknown reason, the read of the colors already takes more than 100 ms :sweat:

let t1 = NSDate() for i in 0..<8 { let inputs = (readLine()!).componentsSeparatedByString(" ") //colors.append((c1:UInt8(inputs[0])!, c2:UInt8(inputs[1])!)) // color of the first & attached block } do { let t2 = NSDate().timeIntervalSinceDate(t1) print("t = \(Int(t2*1000000)) µs", toStream:&errStream) }

t = 191747 µs

Similar to “[Bug] Swift standard code unable to handle the inputs in Stock Exchange Loss puzzle” subject ?

Even this:

while true { let tStart = NSDate() let input = readLine() do { let t2 = NSDate().timeIntervalSinceDate(tStart) print("t = \(Int(t2*1000000)) µs", toStream:&errStream) } break

t = 167989 µs

The first round is particular, you have more time because of language bootstrap and other stuff.
The default code works, you can see that the reading part only takes 10/15ms per round

import Foundation

public struct StderrOutputStream: OutputStreamType {
    public mutating func write(string: String) { fputs(string, stderr) }
}
public var errStream = StderrOutputStream()

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/


// game loop
while true {
    let t1 = NSDate()
    
    for i in 0...7 {
        let inputs = (readLine()!).componentsSeparatedByString(" ")
        let colorA = Int(inputs[0])! // color of the first block
        let colorB = Int(inputs[1])! // color of the attached block
    }
    for i in 0...11 {
        let row = readLine()!
    }
    for i in 0...11 {
        let row = readLine()! // One line of the map ('.' = empty, '0' = skull block, '1' to '5' = colored block)
    }

    // Write an action using print("message...")
    // To debug: debugPrint("Debug messages...", toStream: &errStream)
    let t2 = NSDate().timeIntervalSinceDate(t1)
    print("t = \(Int(t2*1000000)) µs", toStream:&errStream)
    // "x rotation": the column in which to drop your pair of blocks folowed by its rotation (0, 1, 2 or 4)
    print("0 1")
}

OK, thanks ; I have to alter my timeout checker for the first round then ; indeed, I have a parse time of 200 ms for the first round, 23.5 ms for the second, and after a stable 350 µs

1 Like