Sha256: 2f59058fb1deb78a54fa066d2b3a335b95437209934cb967e6714f0603272804

Contents?: true

Size: 540 Bytes

Versions: 63

Compression:

Stored size: 540 Bytes

Contents

import ceylon.collection {
    ArrayList
}

Map<Character,Character> openFor = map { '}'->'{', ')'->'(', ']'->'[' };
Set<Character> opens = set(openFor.items);

Boolean balanced(String brackets) {
    value expectedOpens = ArrayList<Character>();
    for (c in brackets) {
        if (opens.contains(c)) {
            expectedOpens.push(c);
        } else if (exists open = openFor[c]) {
            if ((expectedOpens.pop() else '!') != open) {
                return false;
            }
        }
    }
    return expectedOpens.empty;
}

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.179 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.178 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.177 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.176 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.175 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.174 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.173 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.172 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.171 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.170 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.169 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.167 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.166 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.165 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.164 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.163 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.162 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.161 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon
trackler-2.2.1.160 tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon