trackler 2.0.6.19 → 2.0.6.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/csharp/config.json +8 -0
- data/tracks/csharp/exercises/forth/Example.cs +257 -0
- data/tracks/csharp/exercises/forth/ForthTest.cs +134 -0
- data/tracks/fsharp/config.json +7 -1
- data/tracks/fsharp/exercises/exercises.fsproj +20 -0
- data/tracks/fsharp/exercises/lens-person/Example.fs +50 -0
- data/tracks/fsharp/exercises/lens-person/HINTS.md +2 -0
- data/tracks/fsharp/exercises/lens-person/LensPerson.fs +24 -0
- data/tracks/fsharp/exercises/lens-person/LensPersonTest.fs +43 -0
- data/tracks/fsharp/exercises/paket.references +2 -1
- data/tracks/fsharp/paket.dependencies +1 -0
- data/tracks/fsharp/paket.lock +1 -0
- data/tracks/javascript/exercises/{bob/bob.js → leap/leap.js} +3 -3
- data/tracks/julia/README.md +16 -0
- data/tracks/objective-c/config.json +17 -0
- data/tracks/objective-c/exercises/bracket-push/BracketPushExample.h +8 -0
- data/tracks/objective-c/exercises/bracket-push/BracketPushExample.m +386 -0
- data/tracks/objective-c/exercises/bracket-push/BracketPushTest.m +84 -0
- data/tracks/objective-c/exercises/sublist/SublistExample.h +7 -0
- data/tracks/objective-c/exercises/sublist/SublistExample.m +67 -0
- data/tracks/objective-c/exercises/sublist/SublistTest.m +139 -0
- data/tracks/objective-c/xcodeProject/ObjectiveC.xcodeproj/project.pbxproj +55 -2
- data/tracks/ocaml/exercises/dominoes/test.ml +11 -5
- data/tracks/ocaml/exercises/luhn/test.ml +3 -3
- data/tracks/ocaml/tools/test-generator/templates/dominoes/template.ml +11 -5
- data/tracks/pascal/config.json +1 -1
- data/tracks/pascal/docs/INSTALLATION.md +52 -0
- data/tracks/pascal/docs/img/00delphiwelcomepage.png +0 -0
- data/tracks/pascal/docs/img/01delphiclicktools.png +0 -0
- data/tracks/pascal/docs/img/02delphiclickoptions.png +0 -0
- data/tracks/pascal/docs/img/03delphioptionsenvironmentvariables.png +0 -0
- data/tracks/pascal/docs/img/04delphioptionsenvironmentvariablesclicknew.png +0 -0
- data/tracks/pascal/docs/img/05delphinewuservariable.png +0 -0
- data/tracks/pascal/docs/img/06delphioptionslibrary.png +0 -0
- data/tracks/pascal/docs/img/07delphiclicklibrarypathbutton.png +0 -0
- data/tracks/pascal/docs/img/08delphidirectoriesinputvarnameclickadd.png +0 -0
- data/tracks/pascal/docs/img/09delphidirectoriesclickok.png +0 -0
- data/tracks/pascal/docs/img/10delphioptonsclickok.png +0 -0
- data/tracks/pascal/exercises/nucleotide-count/uNucleotideCountExample.pas +9 -18
- data/tracks/pascal/exercises/nucleotide-count/uNucleotideCountTest.pas +16 -16
- data/tracks/php/config.json +7 -0
- data/tracks/php/exercises/book-store/book-store_test.php +146 -0
- data/tracks/php/exercises/book-store/example.php +38 -0
- data/tracks/swift/docs/TESTS.md +40 -35
- data/tracks/swift/docs/img/tests-fail.png +0 -0
- data/tracks/swift/docs/img/tests-pass.png +0 -0
- data/tracks/swift/docs/img/tests.png +0 -0
- metadata +28 -3
@@ -55,6 +55,26 @@
|
|
55
55
|
</Otherwise>
|
56
56
|
</Choose>
|
57
57
|
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
|
58
|
+
<Choose>
|
59
|
+
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v3.5' Or $(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3')">
|
60
|
+
<ItemGroup>
|
61
|
+
<Reference Include="Aether">
|
62
|
+
<HintPath>..\packages\Aether\lib\net35\Aether.dll</HintPath>
|
63
|
+
<Private>True</Private>
|
64
|
+
<Paket>True</Paket>
|
65
|
+
</Reference>
|
66
|
+
</ItemGroup>
|
67
|
+
</When>
|
68
|
+
<When Condition="($(TargetFrameworkIdentifier) == 'WindowsPhoneApp') Or ($(TargetFrameworkIdentifier) == '.NETCore') Or ($(TargetFrameworkIdentifier) == '.NETStandard' And ($(TargetFrameworkVersion) == 'v1.0' Or $(TargetFrameworkVersion) == 'v1.1' Or $(TargetFrameworkVersion) == 'v1.2' Or $(TargetFrameworkVersion) == 'v1.3' Or $(TargetFrameworkVersion) == 'v1.4' Or $(TargetFrameworkVersion) == 'v1.5' Or $(TargetFrameworkVersion) == 'v1.6')) Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And $(TargetFrameworkVersion) == 'v1.0') Or ($(TargetFrameworkIdentifier) == 'WindowsPhone' And ($(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch') Or ($(TargetFrameworkIdentifier) == 'Xamarin.iOS') Or ($(TargetFrameworkIdentifier) == 'Xamarin.Mac') Or ($(TargetFrameworkProfile) == 'Profile7') Or ($(TargetFrameworkProfile) == 'Profile31') Or ($(TargetFrameworkProfile) == 'Profile32') Or ($(TargetFrameworkProfile) == 'Profile44') Or ($(TargetFrameworkProfile) == 'Profile49') Or ($(TargetFrameworkProfile) == 'Profile78') Or ($(TargetFrameworkProfile) == 'Profile84') Or ($(TargetFrameworkProfile) == 'Profile111') Or ($(TargetFrameworkProfile) == 'Profile151') Or ($(TargetFrameworkProfile) == 'Profile157') Or ($(TargetFrameworkProfile) == 'Profile259')">
|
69
|
+
<ItemGroup>
|
70
|
+
<Reference Include="Aether">
|
71
|
+
<HintPath>..\packages\Aether\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\Aether.dll</HintPath>
|
72
|
+
<Private>True</Private>
|
73
|
+
<Paket>True</Paket>
|
74
|
+
</Reference>
|
75
|
+
</ItemGroup>
|
76
|
+
</When>
|
77
|
+
</Choose>
|
58
78
|
<Choose>
|
59
79
|
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3')">
|
60
80
|
<ItemGroup>
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module LensPerson
|
2
|
+
|
3
|
+
open Aether
|
4
|
+
open Aether.Operators
|
5
|
+
open System
|
6
|
+
|
7
|
+
type Address =
|
8
|
+
{ street: string
|
9
|
+
houseNumber: int
|
10
|
+
place: string
|
11
|
+
country: string }
|
12
|
+
|
13
|
+
static member street_ =
|
14
|
+
(fun a -> a.street), (fun b a -> { a with street = b })
|
15
|
+
|
16
|
+
type Born =
|
17
|
+
{ at: Address
|
18
|
+
on: DateTime }
|
19
|
+
|
20
|
+
static member at_ =
|
21
|
+
(fun a -> a.at), (fun b a -> { a with at = b })
|
22
|
+
|
23
|
+
static member on_ =
|
24
|
+
(fun a -> a.on), (fun b a -> { a with on = b })
|
25
|
+
|
26
|
+
static member birthMonth_ =
|
27
|
+
(fun a -> a.on.Month), (fun b a -> { a with on = DateTime(a.on.Year, b, a.on.Day) })
|
28
|
+
|
29
|
+
type Name =
|
30
|
+
{ name: string
|
31
|
+
surName: string }
|
32
|
+
|
33
|
+
type Person =
|
34
|
+
{ name: Name
|
35
|
+
born: Born
|
36
|
+
address: Address }
|
37
|
+
|
38
|
+
static member born_ =
|
39
|
+
(fun a -> a.born), (fun b a -> { a with born = b })
|
40
|
+
|
41
|
+
static member address_ =
|
42
|
+
(fun a -> a.address), (fun b a -> { a with address = b })
|
43
|
+
|
44
|
+
let bornAtStreet = Person.born_ >-> Born.at_ >-> Address.street_
|
45
|
+
|
46
|
+
let bornOn = Person.born_ >-> Born.on_
|
47
|
+
|
48
|
+
let currentStreet = Person.address_ >-> Address.street_
|
49
|
+
|
50
|
+
let birthMonth = Person.born_ >-> Born.birthMonth_
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module LensPerson
|
2
|
+
|
3
|
+
open Aether
|
4
|
+
open Aether.Operators
|
5
|
+
open System
|
6
|
+
|
7
|
+
type Address =
|
8
|
+
{ street: string
|
9
|
+
houseNumber: int
|
10
|
+
place: string
|
11
|
+
country: string }
|
12
|
+
|
13
|
+
type Born =
|
14
|
+
{ at: Address
|
15
|
+
on: DateTime }
|
16
|
+
|
17
|
+
type Name =
|
18
|
+
{ name: string
|
19
|
+
surName: string }
|
20
|
+
|
21
|
+
type Person =
|
22
|
+
{ name: Name
|
23
|
+
born: Born
|
24
|
+
address: Address }
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module LensPersonTest
|
2
|
+
|
3
|
+
open System
|
4
|
+
open NUnit.Framework
|
5
|
+
open Aether
|
6
|
+
open Aether.Operators
|
7
|
+
open LensPerson
|
8
|
+
|
9
|
+
let testPerson =
|
10
|
+
{ name =
|
11
|
+
{ name = "Jane Joanna"
|
12
|
+
surName = "Doe" }
|
13
|
+
born =
|
14
|
+
{ at =
|
15
|
+
{ street = "Longway"
|
16
|
+
houseNumber = 1024
|
17
|
+
place = "Springfield"
|
18
|
+
country = "United States" }
|
19
|
+
on = DateTime(1984, 4, 12) }
|
20
|
+
address =
|
21
|
+
{ street = "Shortlane"
|
22
|
+
houseNumber = 2
|
23
|
+
place = "Fallmeadow"
|
24
|
+
country = "Canada" } }
|
25
|
+
|
26
|
+
[<Test>]
|
27
|
+
let ``Set born at street`` () =
|
28
|
+
Assert.That(Optic.get bornAtStreet testPerson, Is.EqualTo("Longway"))
|
29
|
+
|
30
|
+
[<Test>]
|
31
|
+
[<Ignore("Remove to run test")>]
|
32
|
+
let ``Set current street`` () =
|
33
|
+
Assert.That(Optic.set currentStreet "Middleroad" testPerson |> Optic.get currentStreet, Is.EqualTo("Middleroad"))
|
34
|
+
|
35
|
+
[<Test>]
|
36
|
+
[<Ignore("Remove to run test")>]
|
37
|
+
let ``Upper case born at street`` () =
|
38
|
+
Assert.That(Optic.map bornAtStreet (fun x -> x.ToUpper()) testPerson |> Optic.get bornAtStreet, Is.EqualTo("LONGWAY"))
|
39
|
+
|
40
|
+
[<Test>]
|
41
|
+
[<Ignore("Remove to run test")>]
|
42
|
+
let ``Set birth month`` () =
|
43
|
+
Assert.That(Optic.set birthMonth 9 testPerson |> Optic.get bornOn, Is.EqualTo(DateTime(1984, 9, 12)))
|
data/tracks/fsharp/paket.lock
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
// convenience to get you started writing code faster.
|
4
4
|
//
|
5
5
|
|
6
|
-
var
|
6
|
+
var Year = function() {};
|
7
7
|
|
8
|
-
|
8
|
+
Year.prototype.isLeap = function(input) {
|
9
9
|
//
|
10
10
|
// YOUR CODE GOES HERE
|
11
11
|
//
|
12
12
|
};
|
13
13
|
|
14
|
-
module.exports =
|
14
|
+
module.exports = Year;
|
data/tracks/julia/README.md
CHANGED
@@ -12,6 +12,8 @@ Please see the [contributing guide](https://github.com/exercism/x-common/blob/ma
|
|
12
12
|
|
13
13
|
## Working on the Exercises
|
14
14
|
|
15
|
+
### Implementing an exercise
|
16
|
+
|
15
17
|
A pool of exercises can be found in the [x-Common repo](https://github.com/exercism/x-common).
|
16
18
|
|
17
19
|
Exercises for the Julia track go in the `exercises` directory and should follow the following filename conventions:
|
@@ -26,5 +28,19 @@ Replace `<slug>` with the exercise slug of the exercise you're working on.
|
|
26
28
|
|
27
29
|
See [Issue #2](https://github.com/exercism/xjulia/issues/2) for discussion on the structure.
|
28
30
|
|
31
|
+
### Adding it to config
|
32
|
+
|
33
|
+
Make sure to add the exercise to the `config.json` file, by adding an entry to the `exercises` array:
|
34
|
+
```json
|
35
|
+
"exercises": [
|
36
|
+
{
|
37
|
+
"slug": "hello-world" ,
|
38
|
+
"difficulty": 1,
|
39
|
+
"topics": ["strings"]
|
40
|
+
}
|
41
|
+
]
|
42
|
+
```
|
43
|
+
If possible, add info on which topics the exercise is about and estimate a difficulty level from 1 to 10. We can adjust these later on when we know more about the exercise and how users solve them.
|
44
|
+
|
29
45
|
### Testing the example solutions
|
30
46
|
Test your example solutions by running `julia runtests.jl` in the project directory. Specify exercise slugs as arguments to run only certain exercises: `julia runtests.jl <slug>`.
|
@@ -105,6 +105,14 @@
|
|
105
105
|
"Filtering"
|
106
106
|
]
|
107
107
|
},
|
108
|
+
{
|
109
|
+
"difficulty": 3,
|
110
|
+
"slug": "sublist",
|
111
|
+
"topics": [
|
112
|
+
"Looping",
|
113
|
+
"Lists"
|
114
|
+
]
|
115
|
+
},
|
108
116
|
{
|
109
117
|
"difficulty": 3,
|
110
118
|
"slug": "clock",
|
@@ -253,6 +261,15 @@
|
|
253
261
|
"Transforming"
|
254
262
|
]
|
255
263
|
},
|
264
|
+
{
|
265
|
+
"difficulty": 5,
|
266
|
+
"slug": "bracket-push",
|
267
|
+
"topics": [
|
268
|
+
"Strings",
|
269
|
+
"Conditionals",
|
270
|
+
"Looping"
|
271
|
+
]
|
272
|
+
},
|
256
273
|
{
|
257
274
|
"difficulty": 5,
|
258
275
|
"slug": "roman-numerals",
|
@@ -0,0 +1,386 @@
|
|
1
|
+
#import "BracketPushExample.h"
|
2
|
+
|
3
|
+
static NSMutableDictionary *parentheses;
|
4
|
+
static NSMutableDictionary *curlyBraces;
|
5
|
+
static NSMutableDictionary *squareBrackets;
|
6
|
+
static NSMutableArray *bracketType;
|
7
|
+
static NSString *inputString = @"";
|
8
|
+
static bool parenthesesPaired = false;
|
9
|
+
static bool curlyBracesPaired = false;
|
10
|
+
static bool squareBracesPaired = false;
|
11
|
+
static bool roundAndCurlyPaired = false;
|
12
|
+
static bool curlyAndSquarePaired =false;
|
13
|
+
static bool roundAndSquarePaired = false;
|
14
|
+
|
15
|
+
@implementation BracketPushExample
|
16
|
+
|
17
|
+
+ (BOOL)validateBracketPairingAndNestingInString:(NSString *)string{
|
18
|
+
|
19
|
+
if([string isEqualToString:@""]){
|
20
|
+
|
21
|
+
return true;
|
22
|
+
}
|
23
|
+
|
24
|
+
inputString = string;
|
25
|
+
parentheses = [NSMutableDictionary dictionary];
|
26
|
+
curlyBraces = [NSMutableDictionary dictionary];
|
27
|
+
squareBrackets = [NSMutableDictionary dictionary];
|
28
|
+
bracketType = [NSMutableArray array];
|
29
|
+
|
30
|
+
[BracketPushExample checkBracketType:@"(" inString:string];
|
31
|
+
[BracketPushExample checkBracketType:@")" inString:string];
|
32
|
+
[BracketPushExample checkBracketType:@"{" inString:string];
|
33
|
+
[BracketPushExample checkBracketType:@"}" inString:string];
|
34
|
+
[BracketPushExample checkBracketType:@"[" inString:string];
|
35
|
+
[BracketPushExample checkBracketType:@"]" inString:string];
|
36
|
+
if(parentheses.count <= 2 && parentheses.count != 0){
|
37
|
+
|
38
|
+
[bracketType addObject:parentheses];
|
39
|
+
}
|
40
|
+
|
41
|
+
if(curlyBraces.count <= 2 && curlyBraces.count != 0){
|
42
|
+
|
43
|
+
[bracketType addObject:curlyBraces];
|
44
|
+
}
|
45
|
+
|
46
|
+
if(squareBrackets.count <= 2 && squareBrackets.count != 0){
|
47
|
+
|
48
|
+
[bracketType addObject:squareBrackets];
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
if([BracketPushExample checkPairingOfAllBrackets]){
|
53
|
+
|
54
|
+
return [BracketPushExample checkBracketNestingForAllBrackets];
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
return false;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
+ (BOOL)checkPairingOfAllBrackets{
|
66
|
+
|
67
|
+
|
68
|
+
bool result = false;
|
69
|
+
parenthesesPaired = [bracketType containsObject:parentheses]?[[parentheses objectForKey:@"("] intValue] == [[parentheses objectForKey:@")"] intValue]:false;
|
70
|
+
curlyBracesPaired = [bracketType containsObject:curlyBraces]?[[curlyBraces objectForKey:@"{"] intValue] == [[curlyBraces objectForKey:@"}"] intValue]:false;
|
71
|
+
squareBracesPaired = [bracketType containsObject:squareBrackets]?[[squareBrackets objectForKey:@"["] intValue] == [[squareBrackets objectForKey:@"]"] intValue]:false;
|
72
|
+
switch((int)bracketType.count){
|
73
|
+
|
74
|
+
case 1: result = [BracketPushExample checkBracketPairingOneAtATime];
|
75
|
+
break;
|
76
|
+
|
77
|
+
case 2: result = [BracketPushExample checkBracketPairingTwoAtATime];
|
78
|
+
break;
|
79
|
+
|
80
|
+
case 3: result = parenthesesPaired && curlyBracesPaired && squareBracesPaired;
|
81
|
+
break;
|
82
|
+
|
83
|
+
default:break;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
return result;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
+ (NSString*)getClosingBracketForOpeningBracket:(NSString*)opener{
|
94
|
+
|
95
|
+
if([opener isEqualToString:@"("]){
|
96
|
+
|
97
|
+
return @")";
|
98
|
+
}else if([opener isEqualToString:@"{"]){
|
99
|
+
|
100
|
+
return @"}";
|
101
|
+
}else if([opener isEqualToString:@"["]){
|
102
|
+
|
103
|
+
return @"]";
|
104
|
+
}
|
105
|
+
|
106
|
+
return @"";
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
+ (BOOL)checkBracketPairingTwoAtATime{
|
112
|
+
|
113
|
+
if(parenthesesPaired && curlyBracesPaired){
|
114
|
+
|
115
|
+
roundAndCurlyPaired=true;
|
116
|
+
|
117
|
+
}else if(curlyBracesPaired && squareBracesPaired){
|
118
|
+
|
119
|
+
curlyAndSquarePaired=true;
|
120
|
+
}else if(squareBracesPaired && parenthesesPaired){
|
121
|
+
|
122
|
+
roundAndSquarePaired=true;
|
123
|
+
}
|
124
|
+
return (roundAndCurlyPaired) || (curlyAndSquarePaired) || (roundAndSquarePaired);
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
+ (BOOL)checkBracketPairingOneAtATime{
|
131
|
+
|
132
|
+
return (parenthesesPaired || curlyBracesPaired || squareBracesPaired);
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
+ (void)checkBracketType:(NSString*)bracket inString:(NSString*)string{
|
138
|
+
|
139
|
+
if([string rangeOfString:bracket].location != NSNotFound){
|
140
|
+
|
141
|
+
if([bracket isEqualToString:@"("] || [bracket isEqualToString:@")"]){
|
142
|
+
|
143
|
+
parentheses[bracket] = [NSNumber numberWithInteger:[string componentsSeparatedByString:bracket].count - 1];
|
144
|
+
|
145
|
+
|
146
|
+
}else if([bracket isEqualToString:@"{"] || [bracket isEqualToString:@"}"]){
|
147
|
+
|
148
|
+
curlyBraces[bracket] = [NSNumber numberWithInteger:[string componentsSeparatedByString:bracket].count - 1];
|
149
|
+
|
150
|
+
}else if([bracket isEqualToString:@"["] || [bracket isEqualToString:@"]"]){
|
151
|
+
|
152
|
+
squareBrackets[bracket] = [NSNumber numberWithInteger:[string componentsSeparatedByString:bracket].count - 1];
|
153
|
+
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
+ (BOOL)checkBracketNestingForAllBrackets{
|
163
|
+
|
164
|
+
bool result = false;
|
165
|
+
switch (bracketType.count) {
|
166
|
+
|
167
|
+
case 1: if([bracketType containsObject:parentheses]){
|
168
|
+
|
169
|
+
result = [BracketPushExample checkNestingOfBracketsOneAtATimeWithOpener:@"(" andCloser:@")"];
|
170
|
+
|
171
|
+
}else if([bracketType containsObject:curlyBraces]){
|
172
|
+
|
173
|
+
result = [BracketPushExample checkNestingOfBracketsOneAtATimeWithOpener:@"{" andCloser:@"}"];
|
174
|
+
|
175
|
+
}else if([bracketType containsObject:squareBrackets]){
|
176
|
+
|
177
|
+
result = [BracketPushExample checkNestingOfBracketsOneAtATimeWithOpener:@"[" andCloser:@"]"];
|
178
|
+
}
|
179
|
+
break;
|
180
|
+
|
181
|
+
|
182
|
+
case 2: if(roundAndCurlyPaired){
|
183
|
+
|
184
|
+
result = [BracketPushExample checkNestingOfBracketsTwoAtATime:@"({"];
|
185
|
+
|
186
|
+
|
187
|
+
}else if(curlyAndSquarePaired){
|
188
|
+
|
189
|
+
result = [BracketPushExample checkNestingOfBracketsTwoAtATime:@"{["];
|
190
|
+
|
191
|
+
}else if(roundAndSquarePaired){
|
192
|
+
|
193
|
+
result = [BracketPushExample checkNestingOfBracketsTwoAtATime:@"[("];
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
break;
|
198
|
+
|
199
|
+
|
200
|
+
case 3: result = [BracketPushExample checkNestingOfBracketsThreeAtATime];
|
201
|
+
break;
|
202
|
+
|
203
|
+
|
204
|
+
default:break;
|
205
|
+
}
|
206
|
+
return result;
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
+ (BOOL)checkNestingOfBracketsOneAtATimeWithOpener:(NSString*)opener andCloser:(NSString*)closer{
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
NSScanner *openScanner = [NSScanner scannerWithString:inputString];
|
217
|
+
NSScanner *closeScanner = [NSScanner scannerWithString:inputString];
|
218
|
+
[openScanner scanUpToString:opener intoString:nil];
|
219
|
+
[closeScanner scanUpToString:closer intoString:nil];
|
220
|
+
while(!openScanner.isAtEnd && !closeScanner.isAtEnd){
|
221
|
+
|
222
|
+
if(openScanner.scanLocation > closeScanner.scanLocation){
|
223
|
+
|
224
|
+
return false;
|
225
|
+
}
|
226
|
+
[openScanner setScanLocation:openScanner.scanLocation+1];
|
227
|
+
[closeScanner setScanLocation:closeScanner.scanLocation+1];
|
228
|
+
[openScanner scanUpToString:opener intoString:nil];
|
229
|
+
[closeScanner scanUpToString:closer intoString:nil];
|
230
|
+
}
|
231
|
+
|
232
|
+
|
233
|
+
return true;
|
234
|
+
}
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
+ (BOOL)checkNestingOfBracketsTwoAtATime:(NSString*)bracketTypeString{
|
240
|
+
|
241
|
+
int opener1Occurence = 0;
|
242
|
+
int closer1Occurence = 0;
|
243
|
+
int opener2Occurence = 0;
|
244
|
+
int closer2Occurence = 0;
|
245
|
+
NSScanner *opener1 = [NSScanner scannerWithString:inputString];
|
246
|
+
NSScanner *closer1= [NSScanner scannerWithString:inputString];
|
247
|
+
NSScanner *opener2= [NSScanner scannerWithString:inputString];
|
248
|
+
NSScanner *closer2= [NSScanner scannerWithString:inputString];
|
249
|
+
|
250
|
+
NSString *openingBracket1 = [NSString stringWithFormat:@"%c",[bracketTypeString characterAtIndex:0]];
|
251
|
+
NSString *openingBracket2 = [NSString stringWithFormat:@"%c",[bracketTypeString characterAtIndex:1]];
|
252
|
+
NSString *closingBracket1 = [BracketPushExample getClosingBracketForOpeningBracket:openingBracket1];
|
253
|
+
NSString *closingBracket2 = [BracketPushExample getClosingBracketForOpeningBracket:openingBracket2];
|
254
|
+
|
255
|
+
[opener1 scanUpToString:openingBracket1 intoString:nil];
|
256
|
+
[opener2 scanUpToString:openingBracket2 intoString:nil];
|
257
|
+
[closer1 scanUpToString:closingBracket1 intoString:nil];
|
258
|
+
[closer2 scanUpToString:closingBracket2 intoString:nil];
|
259
|
+
|
260
|
+
while(!opener1.isAtEnd && !opener2.isAtEnd && !closer1.isAtEnd && !closer2.isAtEnd){
|
261
|
+
|
262
|
+
opener1Occurence++;
|
263
|
+
opener2Occurence++;
|
264
|
+
closer1Occurence++;
|
265
|
+
closer2Occurence++;
|
266
|
+
|
267
|
+
if(opener1.scanLocation < opener2.scanLocation){
|
268
|
+
|
269
|
+
if(closer2.scanLocation != opener2.scanLocation + 1 && closer2.scanLocation > closer1.scanLocation && opener2Occurence == 1){
|
270
|
+
|
271
|
+
|
272
|
+
return false;
|
273
|
+
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
}else{
|
278
|
+
|
279
|
+
if(closer1.scanLocation > closer2.scanLocation && closer1.scanLocation != opener1.scanLocation + 1 && opener1Occurence == 1){
|
280
|
+
|
281
|
+
return false;
|
282
|
+
|
283
|
+
}
|
284
|
+
}
|
285
|
+
[opener1 setScanLocation:opener1.scanLocation+1];
|
286
|
+
[opener2 setScanLocation:opener2.scanLocation+1];
|
287
|
+
[closer1 setScanLocation:closer1.scanLocation+1];
|
288
|
+
[closer2 setScanLocation:closer2.scanLocation+1];
|
289
|
+
[opener1 scanUpToString:openingBracket1 intoString:nil];
|
290
|
+
[opener2 scanUpToString:openingBracket2 intoString:nil];
|
291
|
+
[closer1 scanUpToString:closingBracket1 intoString:nil];
|
292
|
+
[closer2 scanUpToString:closingBracket2 intoString:nil];
|
293
|
+
|
294
|
+
}
|
295
|
+
return true;
|
296
|
+
}
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
+ (BOOL)checkNestingOfBracketsThreeAtATime{
|
303
|
+
|
304
|
+
NSString *orderOfoccurence = [BracketPushExample checkOrderOfOccurenceOfThreeBracketTypes];
|
305
|
+
NSString *opener1 = [NSString stringWithFormat:@"%c",[orderOfoccurence characterAtIndex:0]];
|
306
|
+
NSString *opener2 = [NSString stringWithFormat:@"%c",[orderOfoccurence characterAtIndex:1]];
|
307
|
+
NSString *opener3 = [NSString stringWithFormat:@"%c",[orderOfoccurence characterAtIndex:2]];
|
308
|
+
NSString *closer1 = [BracketPushExample getClosingBracketForOpeningBracket:opener1];
|
309
|
+
NSString *closer2 = [BracketPushExample getClosingBracketForOpeningBracket:opener2];
|
310
|
+
NSString *closer3 = [BracketPushExample getClosingBracketForOpeningBracket:opener3];
|
311
|
+
|
312
|
+
NSScanner *scanner = [NSScanner scannerWithString:inputString];
|
313
|
+
NSScanner *scanner1 = [NSScanner scannerWithString:inputString];
|
314
|
+
NSScanner *scanner2 = [NSScanner scannerWithString:inputString];
|
315
|
+
NSScanner *scanner3 = [NSScanner scannerWithString:inputString];
|
316
|
+
|
317
|
+
[scanner scanUpToString:opener1 intoString:nil];
|
318
|
+
[scanner1 scanUpToString:closer1 intoString:nil];
|
319
|
+
[scanner2 scanUpToString:closer2 intoString:nil];
|
320
|
+
[scanner3 scanUpToString:closer3 intoString:nil];
|
321
|
+
|
322
|
+
while(!scanner.isAtEnd && !scanner1.isAtEnd && !scanner2.isAtEnd && !scanner3.isAtEnd){
|
323
|
+
|
324
|
+
if(scanner1.scanLocation != (scanner.scanLocation + 1) && scanner1.scanLocation < scanner2.scanLocation && scanner1.scanLocation < scanner3.scanLocation){
|
325
|
+
|
326
|
+
return false;
|
327
|
+
}
|
328
|
+
scanner.scanLocation = scanner.scanLocation+1;
|
329
|
+
scanner1.scanLocation = scanner1.scanLocation+1;
|
330
|
+
scanner2.scanLocation = scanner2.scanLocation+1;
|
331
|
+
scanner3.scanLocation = scanner3.scanLocation+1;
|
332
|
+
[scanner scanUpToString:opener1 intoString:nil];
|
333
|
+
[scanner1 scanUpToString:closer1 intoString:nil];
|
334
|
+
[scanner2 scanUpToString:closer2 intoString:nil];
|
335
|
+
[scanner3 scanUpToString:closer3 intoString:nil];
|
336
|
+
}
|
337
|
+
|
338
|
+
return [BracketPushExample checkNestingOfBracketsTwoAtATime:[NSString stringWithFormat:@"%@%@",opener2,opener3]];
|
339
|
+
|
340
|
+
}
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
+ (NSString*)checkOrderOfOccurenceOfThreeBracketTypes{
|
346
|
+
|
347
|
+
NSScanner *scanner1 = [NSScanner scannerWithString:inputString];
|
348
|
+
NSScanner *scanner2 = [NSScanner scannerWithString:inputString];
|
349
|
+
NSScanner *scanner3 = [NSScanner scannerWithString:inputString];
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
[scanner1 scanUpToString:@"(" intoString:nil];
|
354
|
+
[scanner2 scanUpToString:@"{" intoString:nil];
|
355
|
+
[scanner3 scanUpToString:@"[" intoString:nil];
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
if(scanner1.scanLocation < scanner2.scanLocation && scanner1.scanLocation < scanner3.scanLocation){
|
360
|
+
|
361
|
+
if(scanner2.scanLocation < scanner3.scanLocation){
|
362
|
+
|
363
|
+
return @"({[";
|
364
|
+
}
|
365
|
+
return @"([{";
|
366
|
+
}else if(scanner2.scanLocation < scanner1.scanLocation && scanner2.scanLocation < scanner3.scanLocation){
|
367
|
+
|
368
|
+
if(scanner1.scanLocation < scanner3.scanLocation){
|
369
|
+
|
370
|
+
return @"{([";
|
371
|
+
}
|
372
|
+
return @"{[(";
|
373
|
+
|
374
|
+
}
|
375
|
+
|
376
|
+
if(scanner1.scanLocation < scanner2.scanLocation){
|
377
|
+
|
378
|
+
return @"[({";
|
379
|
+
}
|
380
|
+
return @"[{(";
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
}
|
385
|
+
|
386
|
+
@end
|