diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift new file mode 100644 index 0000000..528cfdd --- /dev/null +++ b/Swift/abcdefghppp.swift @@ -0,0 +1,45 @@ +// Tested on Xcode 7.3 Playground +// AB - CD = EF + GH = PPP +// Calcuate based from backward +// EF = PPP-GH and AB = EF+CD + + +import Cocoa + + +var p = 1; + + +for g in 2...9{ + for h in 0...9{ + if h==p||g==h{ + continue} + + var ef = (p*100+p*10+p)-(g*10+h) + var e = ef/10 + var f = ef%10 + if e==f || e==p || f==p || e==g || e==h || f==g || f==h{ + continue + } + + + for c in 2...9{ + for d in 0...9{ + if d==p||c==e||d==e||c==f||d==f||c==g||d==g||c==h||d==h||c==d{ + continue} + var ab = ef+c*10+d + if ab>99{ + break} + + var a = ab/10 + var b = ab%10 + if a==p||b==p||a==e||b==e||a==f||b==f||a==g||b==g||a==h||b==h||a==c||b==c||a==d||a==d||a==b{ + continue} + print("AB \(a)\(b)- CD \(c)\(d) = EF \(e)\(f) +GH \(g)\(h) = \(p)\(p)\(p)") + + } + } + + } +} + diff --git a/Swift/output.txt b/Swift/output.txt new file mode 100644 index 0000000..fed7d33 --- /dev/null +++ b/Swift/output.txt @@ -0,0 +1,5 @@ +AB 95- CD 27 = EF 68 +GH 43 = 111 +AB 90- CD 27 = EF 63 +GH 48 = 111 +AB 85- CD 46 = EF 39 +GH 72 = 111 +AB 86- CD 54 = EF 32 +GH 79 = 111 +AB 90- CD 63 = EF 27 +GH 84 = 111