File tree 2 files changed +2584
-0
lines changed
2022/Day 2: Rock Paper Scissors/part-2
2 files changed +2584
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "io/ioutil"
6
+ "strings"
7
+ )
8
+
9
+ func win (x , y rune ) int {
10
+ if x == 'A' && y == 'Y' {
11
+ return 6
12
+ }
13
+ if x == 'B' && y == 'Z' {
14
+ return 6
15
+ }
16
+ if x == 'C' && y == 'X' {
17
+ return 6
18
+ }
19
+
20
+ if (x == 'A' && y == 'X' ) || (x == 'B' && y == 'Y' ) || (x == 'C' && y == 'Z' ) {
21
+ return 3
22
+ }
23
+
24
+ return 0
25
+ }
26
+
27
+ func scoreMove (x rune ) int {
28
+ if x == 'X' {
29
+ return 1
30
+ } else if x == 'Y' {
31
+ return 2
32
+ }
33
+
34
+ return 3
35
+ }
36
+
37
+ func myMove (oppMove rune , result rune ) rune {
38
+ if result == 'Z' {
39
+ if oppMove == 'A' {
40
+ return 'Y'
41
+ }
42
+ if oppMove == 'B' {
43
+ return 'Z'
44
+ }
45
+
46
+ return 'X'
47
+ } else if result == 'X' {
48
+ if oppMove == 'A' {
49
+ return 'Z'
50
+ }
51
+ if oppMove == 'B' {
52
+ return 'X'
53
+ }
54
+
55
+ return 'Y'
56
+ } else {
57
+ if oppMove == 'A' {
58
+ return 'X'
59
+ }
60
+ if oppMove == 'B' {
61
+ return 'Y'
62
+ }
63
+
64
+ return 'Z'
65
+ }
66
+
67
+ return oppMove
68
+ }
69
+
70
+ func main () {
71
+ bytesRead , _ := ioutil .ReadFile ("input.txt" )
72
+ fileContent := string (bytesRead )
73
+ lines := strings .Split (fileContent , "\n " )
74
+
75
+ var score int
76
+ for _ , line := range lines {
77
+ first , res := rune (line [0 ]), rune (line [2 ])
78
+ second := myMove (first , res )
79
+ score += win (first , second ) + scoreMove (second )
80
+ // fmt.Println(score)
81
+ }
82
+
83
+ fmt .Println (score )
84
+ }
You can’t perform that action at this time.
0 commit comments