Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Swift/abcdefghppp.swift
Original file line number Diff line number Diff line change
@@ -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)")

}
}

}
}

5 changes: 5 additions & 0 deletions Swift/output.txt
Original file line number Diff line number Diff line change
@@ -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