Created
June 25, 2018 14:43
-
-
Save marslin1220/12f5ba33e5ec51c6dc70fb5e95335b00 to your computer and use it in GitHub Desktop.
Print swift script like a type machine by script self.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
// | |
// SelfPrinter.swift | |
// SelfPrinter | |
// | |
// Created by Lin Cheng Lung on 2018/6/25. | |
// Copyright © 2018 Lin Cheng Lung. All rights reserved. | |
// | |
import Foundation | |
let filePosition = CommandLine.arguments[0] | |
let fileContent = try! String(contentsOfFile: filePosition) | |
for char in Array(fileContent) { | |
print(char, terminator: "") | |
fflush(__stdoutp) | |
if char == " " { | |
usleep(arc4random_uniform(300000) + 100000) | |
} else { | |
usleep(arc4random_uniform(150000) + 50000) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment