From bc197a226b725fce8f8a78cab87e3376cf002e61 Mon Sep 17 00:00:00 2001 From: evec Date: Fri, 25 Mar 2016 21:51:39 +0800 Subject: [PATCH 01/11] Swift version of AB - CD = EF + GH = PPP AB - CD = EF + GH = PPP Example for Swift as use backward finding. --- Swift/abcdefghppp.swift | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Swift/abcdefghppp.swift diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift new file mode 100644 index 0000000..71b8ec6 --- /dev/null +++ b/Swift/abcdefghppp.swift @@ -0,0 +1,37 @@ +//: Tested on Xcode 7.3 Playground + +import Cocoa + + +var p = 1; + +// g start from 1 because no 0 and p=1 +for g in 2...9{ + for h in 0...9{ + if h==p||g==h{ + continue} + // ef = 111-gh + var ef = (p*100+p*10+p)-(g*10+h) + var e = ef/10 + var f = ef%10 + + //ef + cd = ab + for c in 1...9{ + for d in 0...9{ + if c==p||d==p||c==e||d==e||c==f||d==f||c==g||d==g||c==f||d==f||c==d{ + continue} + var ab = ef+c*10+d + if ab>99{ + continue} + + 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==f||b==f||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)") + + } + } + + } +} From 2e03469a2abf065bdff7f74c9ae053d17c8aaf02 Mon Sep 17 00:00:00 2001 From: evec Date: Fri, 25 Mar 2016 22:04:06 +0800 Subject: [PATCH 02/11] Update abcdefghppp.swift Mistake checking code --- Swift/abcdefghppp.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift index 71b8ec6..21578b0 100644 --- a/Swift/abcdefghppp.swift +++ b/Swift/abcdefghppp.swift @@ -18,7 +18,7 @@ for g in 2...9{ //ef + cd = ab for c in 1...9{ for d in 0...9{ - if c==p||d==p||c==e||d==e||c==f||d==f||c==g||d==g||c==f||d==f||c==d{ + if c==p||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{ @@ -26,7 +26,7 @@ for g in 2...9{ 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==f||b==f||a==c||b==c||a==d||a==d||a==b{ + 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)") From ff4d9acaa49eca5e4d81fab84c4d5d4b26e97e8f Mon Sep 17 00:00:00 2001 From: evec Date: Fri, 25 Mar 2016 22:18:23 +0800 Subject: [PATCH 03/11] Update abcdefghppp.swift should check e is not equal to f --- Swift/abcdefghppp.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift index 21578b0..f093e0f 100644 --- a/Swift/abcdefghppp.swift +++ b/Swift/abcdefghppp.swift @@ -14,6 +14,9 @@ for g in 2...9{ var ef = (p*100+p*10+p)-(g*10+h) var e = ef/10 var f = ef%10 + if e==f{ + continue + } //ef + cd = ab for c in 1...9{ From 674246843e42c13655cd31e61ef9aa6418fd3d5a Mon Sep 17 00:00:00 2001 From: evec Date: Fri, 25 Mar 2016 22:28:38 +0800 Subject: [PATCH 04/11] Update abcdefghppp.swift --- Swift/abcdefghppp.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift index f093e0f..528cb6c 100644 --- a/Swift/abcdefghppp.swift +++ b/Swift/abcdefghppp.swift @@ -25,7 +25,7 @@ for g in 2...9{ continue} var ab = ef+c*10+d if ab>99{ - continue} + break} var a = ab/10 var b = ab%10 From 4f900a02ee3128ad87aceb0f3f591abdd05b7409 Mon Sep 17 00:00:00 2001 From: evec Date: Fri, 25 Mar 2016 22:50:04 +0800 Subject: [PATCH 05/11] Update abcdefghppp.swift --- Swift/abcdefghppp.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift index 528cb6c..3477c3e 100644 --- a/Swift/abcdefghppp.swift +++ b/Swift/abcdefghppp.swift @@ -1,4 +1,5 @@ -//: Tested on Xcode 7.3 Playground +/ Tested on Xcode 7.3 Playground +// AB - CD = EF + GH = PPP import Cocoa @@ -14,14 +15,14 @@ for g in 2...9{ var ef = (p*100+p*10+p)-(g*10+h) var e = ef/10 var f = ef%10 - if e==f{ + if e==f || e==1 || f==1{ continue } //ef + cd = ab - for c in 1...9{ + for c in 2...9{ for d in 0...9{ - if c==p||d==p||c==e||d==e||c==f||d==f||c==g||d==g||c==h||d==h||c==d{ + 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{ From fc7df2ebce7bae4596ac5938eca13b175d8976a1 Mon Sep 17 00:00:00 2001 From: evec Date: Fri, 25 Mar 2016 22:51:06 +0800 Subject: [PATCH 06/11] Create output.txt --- Swift/output.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Swift/output.txt diff --git a/Swift/output.txt b/Swift/output.txt new file mode 100644 index 0000000..95bb56f --- /dev/null +++ b/Swift/output.txt @@ -0,0 +1,29 @@ +AB 95- CD 27 = EF 68 +GH 43 = 111 +AB 93- CD 28 = EF 65 +GH 46 = 111 +AB 97- CD 32 = EF 65 +GH 46 = 111 +AB 89- CD 25 = EF 64 +GH 47 = 111 +AB 90- CD 27 = EF 63 +GH 48 = 111 +AB 80- CD 23 = EF 57 +GH 54 = 111 +AB 83- CD 26 = EF 57 +GH 54 = 111 +AB 86- CD 29 = EF 57 +GH 54 = 111 +AB 89- CD 32 = EF 57 +GH 54 = 111 +AB 80- CD 26 = EF 54 +GH 57 = 111 +AB 83- CD 29 = EF 54 +GH 57 = 111 +AB 86- CD 32 = EF 54 +GH 57 = 111 +AB 90- CD 36 = EF 54 +GH 57 = 111 +AB 92- CD 38 = EF 54 +GH 57 = 111 +AB 79- CD 26 = EF 53 +GH 58 = 111 +AB 86- CD 34 = EF 52 +GH 59 = 111 +AB 82- CD 35 = EF 47 +GH 64 = 111 +AB 78- CD 32 = EF 46 +GH 65 = 111 +AB 85- CD 46 = EF 39 +GH 72 = 111 +AB 90- CD 52 = EF 38 +GH 73 = 111 +AB 92- CD 54 = EF 38 +GH 73 = 111 +AB 94- CD 56 = EF 38 +GH 73 = 111 +AB 65- CD 28 = EF 37 +GH 74 = 111 +AB 89- CD 52 = EF 37 +GH 74 = 111 +AB 86- CD 54 = EF 32 +GH 79 = 111 +AB 64- CD 35 = EF 29 +GH 82 = 111 +AB 75- CD 46 = EF 29 +GH 82 = 111 +AB 95- CD 67 = EF 28 +GH 83 = 111 +AB 90- CD 63 = EF 27 +GH 84 = 111 From 478157b5d58e96f5e06f4045342de489b1910df6 Mon Sep 17 00:00:00 2001 From: evec Date: Sat, 26 Mar 2016 02:12:11 +0800 Subject: [PATCH 07/11] Update abcdefghppp.swift Mistake fixed - check of EF is not equal of GH --- Swift/abcdefghppp.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift index 3477c3e..270c7ea 100644 --- a/Swift/abcdefghppp.swift +++ b/Swift/abcdefghppp.swift @@ -1,4 +1,4 @@ -/ Tested on Xcode 7.3 Playground +// Tested on Xcode 7.3 Playground // AB - CD = EF + GH = PPP import Cocoa @@ -15,7 +15,7 @@ for g in 2...9{ var ef = (p*100+p*10+p)-(g*10+h) var e = ef/10 var f = ef%10 - if e==f || e==1 || f==1{ + if e==f || e==p || f==p || e==g || e==h || f==g || f==h{ continue } @@ -39,3 +39,4 @@ for g in 2...9{ } } + From 9b84eb83db08dbaf1871ec1bca5982a5fd86dadd Mon Sep 17 00:00:00 2001 From: evec Date: Sat, 26 Mar 2016 02:12:53 +0800 Subject: [PATCH 08/11] Update output.txt Correct Output --- Swift/output.txt | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/Swift/output.txt b/Swift/output.txt index 95bb56f..a6bda7c 100644 --- a/Swift/output.txt +++ b/Swift/output.txt @@ -2,28 +2,8 @@ AB 95- CD 27 = EF 68 +GH 43 = 111 AB 93- CD 28 = EF 65 +GH 46 = 111 AB 97- CD 32 = EF 65 +GH 46 = 111 AB 89- CD 25 = EF 64 +GH 47 = 111 +AB 95- CD 27 = EF 68 +GH 43 = 111 AB 90- CD 27 = EF 63 +GH 48 = 111 -AB 80- CD 23 = EF 57 +GH 54 = 111 -AB 83- CD 26 = EF 57 +GH 54 = 111 -AB 86- CD 29 = EF 57 +GH 54 = 111 -AB 89- CD 32 = EF 57 +GH 54 = 111 -AB 80- CD 26 = EF 54 +GH 57 = 111 -AB 83- CD 29 = EF 54 +GH 57 = 111 -AB 86- CD 32 = EF 54 +GH 57 = 111 -AB 90- CD 36 = EF 54 +GH 57 = 111 -AB 92- CD 38 = EF 54 +GH 57 = 111 -AB 79- CD 26 = EF 53 +GH 58 = 111 -AB 86- CD 34 = EF 52 +GH 59 = 111 -AB 82- CD 35 = EF 47 +GH 64 = 111 -AB 78- CD 32 = EF 46 +GH 65 = 111 AB 85- CD 46 = EF 39 +GH 72 = 111 -AB 90- CD 52 = EF 38 +GH 73 = 111 -AB 92- CD 54 = EF 38 +GH 73 = 111 -AB 94- CD 56 = EF 38 +GH 73 = 111 -AB 65- CD 28 = EF 37 +GH 74 = 111 -AB 89- CD 52 = EF 37 +GH 74 = 111 AB 86- CD 54 = EF 32 +GH 79 = 111 -AB 64- CD 35 = EF 29 +GH 82 = 111 -AB 75- CD 46 = EF 29 +GH 82 = 111 -AB 95- CD 67 = EF 28 +GH 83 = 111 AB 90- CD 63 = EF 27 +GH 84 = 111 From 46a768c81554d50122e265034cc73fe91770b62c Mon Sep 17 00:00:00 2001 From: evec Date: Sat, 26 Mar 2016 02:13:48 +0800 Subject: [PATCH 09/11] Update output.txt Correct Output --- Swift/output.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Swift/output.txt b/Swift/output.txt index a6bda7c..fed7d33 100644 --- a/Swift/output.txt +++ b/Swift/output.txt @@ -1,8 +1,4 @@ AB 95- CD 27 = EF 68 +GH 43 = 111 -AB 93- CD 28 = EF 65 +GH 46 = 111 -AB 97- CD 32 = EF 65 +GH 46 = 111 -AB 89- CD 25 = EF 64 +GH 47 = 111 -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 From 2db15d9a416ab8ed756e5923585a522d26c7bb5d Mon Sep 17 00:00:00 2001 From: evec Date: Sat, 26 Mar 2016 02:24:29 +0800 Subject: [PATCH 10/11] Update abcdefghppp.swift --- Swift/abcdefghppp.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift index 270c7ea..6c09309 100644 --- a/Swift/abcdefghppp.swift +++ b/Swift/abcdefghppp.swift @@ -6,7 +6,7 @@ import Cocoa var p = 1; -// g start from 1 because no 0 and p=1 +// g start from 2 because no 0 and p=1 for g in 2...9{ for h in 0...9{ if h==p||g==h{ From 4877b4ad8e81f94557669f44ab1c4993a28dfcab Mon Sep 17 00:00:00 2001 From: evec Date: Sat, 26 Mar 2016 17:32:58 +0800 Subject: [PATCH 11/11] Update abcdefghppp.swift Change all commit to begin --- Swift/abcdefghppp.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Swift/abcdefghppp.swift b/Swift/abcdefghppp.swift index 6c09309..528cfdd 100644 --- a/Swift/abcdefghppp.swift +++ b/Swift/abcdefghppp.swift @@ -1,17 +1,20 @@ // 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; -// g start from 2 because no 0 and p=1 + for g in 2...9{ for h in 0...9{ if h==p||g==h{ continue} - // ef = 111-gh + var ef = (p*100+p*10+p)-(g*10+h) var e = ef/10 var f = ef%10 @@ -19,7 +22,7 @@ for g in 2...9{ continue } - //ef + cd = ab + 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{