-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoolkit.nu
More file actions
executable file
·105 lines (92 loc) · 2.36 KB
/
toolkit.nu
File metadata and controls
executable file
·105 lines (92 loc) · 2.36 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env nu
def --wrapped main [...rest] {
const pathToSelf = path self
let nameOfSelf = $pathToSelf | path parse | get stem
if $rest in [ [-h] [--help] ] {
^$nu.current-exe -c $'use ($pathToSelf); scope modules | where name == ($nameOfSelf) | get 0.commands.name'
} else {
^$nu.current-exe -c $'use ($pathToSelf); ($nameOfSelf) ($rest | str join (" "))'
}
}
export def download-challenge [problemNumber] {
const path_to_src_folder = [(path self) .. project_euler] | path join
let file = http get $"https://projecteuler.net/problem=($problemNumber)"
| parse '<title>#{number} {title} - Project Euler</title>'
| get title.0
| str snake-case
| {
parent: $path_to_src_folder
stem: $"test_pe($problemNumber)_($in)"
extension: py
}
| path join
http get $"https://projecteuler.net/minimal=($problemNumber)"
| lines
| each { $"# ($in)" }
| prepend $"# <https://projecteuler.net/problem=($problemNumber)>"
| append [ $"# Notes:" "# " ]
| str join (char newline)
| save $file
}
export def update-readme [] {
$"
<div align=\"center\">
<img src=\"https://projecteuler.net/profile/NonlinearFruit.png\"/>
<img src=\"https://projecteuler.net/profile/unclebobmartin.png\"/>
<img src=\"https://projecteuler.net/profile/africh.png\"/>
</div>
# [Project Euler]\(https://projecteuler.net)
## Solutions
(table-of-scores)
## How To
- [required] pdm <https://github.com/pdm-project/pdm>
- [required] `pdm install`
```sh
./toolkit.nu download-challenge $CHALLENGE
git add -A
vim project_euler/ # Edit challenge
pdm test # Run tests
./toolkit.nu update-readme
git add -A
git commit -m \"Solve PE $CHALLENGE: $TITLE\"
```
## Help
(help-docs)
"
| save -f README.md
}
def table-of-scores [] {
ls project_euler/test_*
| each {|file|
$file.name
| path parse
| get stem
| parse "test_pe{number}_{challenge}"
| first
| update number { into int }
| update challenge { str title-case }
| insert links {|it|
$"\([src]\(($file.name))) \([web]\(https://projecteuler.net/problem=($it.number)))"
}
}
| sort-by number
| to md
}
def help-docs [] {
scope modules
| where name == toolkit
| get commands.0.name
| each {|cmd|
^nu -c $"use toolkit.nu; toolkit ($cmd) -h"
| str trim
| $"
<details><summary>toolkit ($cmd)</summary>
```
($in)
```
</details>
"
}
| to text
| ansi strip
}