Last active
August 29, 2015 14:02
-
-
Save nacookan/e8def2ec92fb9bb07344 to your computer and use it in GitHub Desktop.
Swiftでジョン・ボン・ジョヴィ (via https://twitter.com/yagiyyyy/status/473405016540053504)
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
import Cocoa | |
var a = ["ボ","ン","ジョ","ヴィ"] | |
var c = 0, j = false, b = false | |
while(true) { | |
var r1 = arc4random() % 4 | |
var r2 = arc4random() % 4 | |
print((0 < c++ ? "・" : "") + a[Int(r1)] + a[Int(r2)]) | |
if !j && !b { | |
if r1 == 2 && r2 == 1 { | |
j = true | |
} | |
}else if j && !b{ | |
if r1 == 0 && r2 == 1 { | |
b = true | |
} else { | |
j = false | |
} | |
}else if j && b { | |
if r1 == 2 && r2 == 3 { | |
print("\n\(c) Bon Jovis") | |
break | |
} else { | |
b = false | |
j = false | |
} | |
} | |
} | |
/* 別バージョン | |
import Cocoa | |
var a = ["ボ", "ン", "ジョ", "ヴィ"] | |
var l:Int[] = [] | |
while(true) { | |
var r = Int(arc4random() % 4) | |
print((0 < l.count && l.count % 2 == 0 ? "・" : "") + a[r]) | |
l += r | |
if 6 <= l.count && Array(l[(l.count-6)..(l.count)]) == [2,1,0,1,2,3] { | |
print("\n\(l.count / 2) Bon Jovis") | |
break | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment