-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.go
65 lines (57 loc) · 1.59 KB
/
3.go
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
package main
import (
"fmt"
"os"
"io/ioutil"
"net/http"
"strings"
_"strconv"
)
var Map [6]string
func main() {
// got the map
//for _, line := range Map { fmt.Println("Map/", line) }
// get the steps
URL := "https://challenges.aquaq.co.uk/challenge/3/input.txt"
body := strings.TrimSpace(string(getbody(URL)))
res := 0
r, c := 0, 2
N := len(body)
for i := 0; i < N; i++ {
char := string(body[i])
if char == "U" && r - 1 >= 0 && string(Map[r - 1][c]) == "#" {r -= 1}
if char == "D" && r + 1 <= 5 && string(Map[r + 1][c]) == "#" {r += 1}
if char == "L" && c - 1 >= 0 && string(Map[r][c - 1]) == "#" {c -= 1}
if char == "R" && c + 1 <= 5 && string(Map[r][c + 1]) == "#" {c += 1}
res += r + c
}
fmt.Println("res/" + Yell, res, Rest)
}
func init() {
Map[0] = " ## "
Map[1] = " #### "
Map[2] = "######"
Map[3] = "######"
Map[4] = " #### "
Map[5] = " ## "
}
func getbody(URL string) []uint8 {
session_value := os.Getenv("COOK")
if session_value == "" {
panic("session/empty")
}
conn := &http.Client {}
req, _ := http.NewRequest("GET", URL, nil)
session := &http.Cookie {
Name: "session",
Value: session_value,
}
req.AddCookie( session )
resp, _ := conn.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return body
}
const Yell, Cyan, Rest string = "\033[33m", "\033[36m", "\033[0m"
func YELL(s string)string{ return Yell + s + Rest }
func CYAN(s string)string{ return Cyan + s + Rest }