-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.go
76 lines (70 loc) · 2.19 KB
/
13.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
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"os"
"io/ioutil"
"net/http"
"strings"
)
func main() {
URL := "https://challenges.aquaq.co.uk/challenge/13/input.txt"
lines := strings.Split(strings.TrimSpace(string(getbody(URL))), "\n")
//for _, line := range lines {fmt.Println("line/", CYAN(line[:17]), "...") }
lines = []string{ "ABCABCABCABCABC", "AAAAAAB", "ABCABCABCABCABCAAAAAAB" }
var max_repetion_bruteforce func(s string) (int, string)
max_repetion_bruteforce = func(s string) (int, string) {
pattern := ""
count := 1
N := len(s)
// DBG
// fmt.Println( CYAN ("\n" + s))
for i := range s {
size := 1
for size < N - i + 1 {
curr := 0
substr := s[i : i + size]
// DBG
// fmt.Println( YELL ("\n" + substr))
for i + size * curr < N + 1 && i + size * (curr + 1) < N + 1 &&
s[i + size * curr : i + size * (curr + 1)] == substr {
// DBG
//fmt.Println(s[i + size * curr : i + size * (curr + 1)], substr, curr)
curr++
}
if count < curr {
count = curr
pattern = substr
}
size++
}
}
return count, pattern
}
res := 0
for _, line := range lines {
size, pattern := max_repetion_bruteforce (line)
fmt.Println(size, YELL (pattern))
res += size
}
fmt.Println("res/" + Cyan, res, Rest)
}
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 }