aboutsummaryrefslogtreecommitdiff
path: root/challenge-273/spadacciniweb/go/ch-2.go
blob: 509565840e5f53846df87ffa22f6b1b7877c0600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Task 2: B After A
Submitted by: Mohammad Sajid Anwar

You are given a string, $str.
Write a script to return true if there is at least one b, and no a appears after the first b.

Example 1
Input: $str = "aabb"
Output: true

Example 2
Input: $str = "abab"
Output: false

Example 3
Input: $str = "aaa"
Output: false

Example 4
Input: $str = "bbb"
Output: true
*/

package main

import (
    "fmt"
    s "strings"
)

func position (str string) {
    offset := s.Index(str, "b")
    res := 0
    
    if (offset >=0) {
        res = s.Index( str[offset+1:], "a");
    }

    if (res == -1) {
        fmt.Printf("%s -> %s\n", str, "true")
    } else {
        fmt.Printf("%s -> %s\n", str, "false")
    }
}

func main() {
    str := "aabb"
    position(str)

    str = "abab";
    position(str)

    str = "aaa"
    position(str)

    str = "bbb"
    position(str)
}