-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathans.go
More file actions
52 lines (45 loc) · 948 Bytes
/
ans.go
File metadata and controls
52 lines (45 loc) · 948 Bytes
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
package ans
import (
"fmt"
"github.com/pkg/browser"
)
// Prints out solution for problem p
func Sol(p int) {
x := 1
defer recAns(p, &x)
var fn func() = solMap[p]
x = 2
fn()
}
// Runs interactive solution for problem p
func Ask(p int) {
x := 1
defer recAns(p, &x)
var fn func() = askMap[p]
x = 2
fn()
}
// Opens writeup for problem p on my personal blog site
// DEPRECATED
//func Writeup(p int) {
// var gURL string = "https://heen.dev/writeup/euler/" + strconv.Itoa(p)
// fmt.Println("Heading to", gURL)
// browser.OpenURL(gURL)
//}
// Opens my repo's main page on Github
func Repo() {
var gURL string = "https://github.com/aaheen/euler"
fmt.Println("Heading to", gURL)
browser.OpenURL(gURL)
}
// Recovers if Sol or Ask fail
func recAns(p int, x *int) {
if err := recover(); err != nil {
switch *x {
case 1:
panic(fmt.Sprintf("Solution to problem %d has not been implemented yet", p))
case 2:
panic(err)
}
}
}