aboutsummaryrefslogtreecommitdiff
path: root/2021/09/first.go
blob: edfca875b1bf94f3f338d018f7a10cc47597b6b7 (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
61
62
63
64
65
66
67
68
69
package main

import (
	"bufio"
	"fmt"
	"os"
)

// DOES NOT WORK!!!

func countMins(prev []byte, prevS []bool) (score int) {
	for i, v := range prevS {
		if v {
			fmt.Println(prev[i])
			score += int(prev[i]) + 1
		}
	}
	return
}

func main() {
	score := 0

	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	width := len(s.Text())
	prevS := make([]bool, width)
	prev := make([]byte, width)
	for i, ch := range s.Text() {
		prev[i] = byte(ch) - '0'
		if i == 0 {
			prevS[i] = true
		} else if prev[i] < prev[i-1] {
			prevS[i-1] = false
			prevS[i] = true
		}
	}

	curS := make([]bool, width)
	cur := make([]byte, width)
	fmt.Println(s.Text())
	for s.Scan() {
		for i, ch := range s.Text() {
			cur[i] = byte(ch) - '0'
			if i > 0 && cur[i] < cur[i-1] {
				curS[i-1] = false
				if cur[i] < prev[i] {
					prevS[i] = false
					curS[i] = true
				} else {
					curS[i] = false
				}
			} else {
				if cur[i] < prev[i] {
					prevS[i] = false
				}
				curS[i] = false
			}
		}
		fmt.Printf("%+v\n", prevS)
		fmt.Println(s.Text())
		score += countMins(prev, prevS)
		copy(prev, cur)
		copy(prevS, curS)
	}
	score += countMins(prev, prevS)
	fmt.Printf("%+v\n", prevS)
	fmt.Println(score)
}