Skip to content

Commit 3d73666

Browse files
committedSep 1, 2022
feat: sunset spr in favor of native cargo commands and cargo-generate
1 parent 97577b4 commit 3d73666

File tree

10 files changed

+74
-506
lines changed

10 files changed

+74
-506
lines changed
 

‎.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ utils
44
*.py
55
src/main.rs
66
Cargo.lock
7-
Cargo.toml
87
target
98
rust_builds
109
tests/overrandomized.in
1110
rls
12-
!spr/Cargo.toml
13-
!spr/Cargo.lock
1411
!src/**/Cargo.toml
1512
!template/Cargo.toml
1613
.vscode/
14+
.rustc_info.json
15+
release

‎Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[workspace]
2+
members = ["./src/*/src/.."]
3+

‎README.md

+10-32
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Solutions to Kick Start Problems, Codeforces and CodeJam are all mixed up in the
88

99
## Quick start
1010

11-
In this competitions speed is everything, that's why there's a file, `src/example.src`, which can be used to start solving a problem.
11+
In this competitions speed is everything, that's why there's a file, `template/src/main.src`, which can be used to start solving a problem.
1212

1313
It contains number parsing, and vector parsing for `i32`, `usize`, `u32`, etc. All generics that implement `FromStr`.
1414

@@ -49,49 +49,27 @@ fn main() -> Res<()> {
4949
}
5050
```
5151

52-
## `spr`
52+
## Creating a new problem
5353

54-
`spr` is a Rust CLI to simplify and speed up problem solving.
55-
56-
It has two modes, `create` and `run`. The default mode is to `run`.
57-
58-
### Compiling
59-
60-
From the root of the project:
54+
Enter to the `src` folder and run:
6155

6256
```
63-
cd spr
57+
cargo generate --path ./template --name <problem_name> --force
6458
```
6559

66-
Build the binary:
60+
## Solving a problem
6761

68-
```
69-
cargo build --release
70-
```
62+
Place your solution inside the `main` function. Create as many helpers as necessary.
7163

72-
### Creating a new problem
64+
## Run a problem
7365

74-
From the root of the project:
66+
From the problem directory:
7567

7668
```
77-
./spr/target/release/spr <problem-name> -m create
69+
cargo build --release --target-dir .
70+
./release/<problem_name> < <problem_name>.in
7871
```
7972

80-
This copies the contents of `src/example.rs` to `src/<problem-name>.rs` and also creates a test file `tests/<problem-name>.in`.
81-
82-
### Run a problem
83-
84-
From the root of the project:
85-
86-
```
87-
./spr/target/release/spr <problem-name>
88-
```
89-
90-
This runs `rustc src/<problem-name>.rs --out-dir rls` and then pipes `tests/<problem-name>.in` to `./rls/<problem-name>`.
91-
92-
- If an error should occur at any stage, the error message shows in the `stdout`.
93-
- If all goes well, then your program output shows in the `stdin`.
94-
9573
## Legacy
9674

9775
### CodeJam 2019

‎spr/Cargo.lock

-394
This file was deleted.

‎spr/src/main.rs

-69
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
2-
name = "spr"
3-
version = "0.1.0"
42
authors = ["Joseph Chamochumbi <sephxd1234@gmail.com>"]
53
edition = "2018"
4+
name = "seven-segment-display"
5+
version = "0.1.0"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/car
8+
9+
10+
11+
612

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
813

9-
[dependencies]
10-
structopt = "0.3.13"
11-
confy = "0.4.0"
12-
serde= "^1.0"
13-
serde_derive= "^1.0"

‎src/seven-segment-display/input.in

Whitespace-only changes.

‎src/seven-segment-display/src/main.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use std::io;
2+
3+
fn main() -> Res<()> {
4+
let n = parse_num::<u32>();
5+
for case in 1..=n {
6+
println!("Case #{}: {}", case, 0);
7+
}
8+
9+
Ok(())
10+
}
11+
12+
type Res<T> = Result<T, Box<dyn std::error::Error>>;
13+
14+
fn nxt() -> String {
15+
let mut input = String::new();
16+
match io::stdin().read_line(&mut input) {
17+
Ok(_) => input,
18+
_ => panic!("Error reading line"),
19+
}
20+
}
21+
22+
fn parse_num<T: std::str::FromStr>() -> T {
23+
match nxt().trim().parse::<T>() {
24+
Ok(n) => n,
25+
_ => panic!("Error parsing"),
26+
}
27+
}
28+
29+
#[allow(dead_code)]
30+
fn parse_vec<T: std::str::FromStr>() -> Vec<T> {
31+
nxt()
32+
.split_whitespace()
33+
.map(|x| match x.parse::<T>() {
34+
Ok(n) => n,
35+
_ => panic!("Could not parse vector"),
36+
})
37+
.collect()
38+
}
39+
40+
#[allow(dead_code)]
41+
fn string_vec<T: std::string::ToString>(vec: &Vec<T>, separator: &str) -> String {
42+
vec.iter()
43+
.map(|x| x.to_string())
44+
.collect::<Vec<String>>()
45+
.join(separator)
46+
}

‎template/input.in

Whitespace-only changes.

‎tests/seven-segment-display.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
4
2+
1 1111111
3+
2 0000000 0001010
4+
3 0100000 0000111 0000011
5+
5 1011011 1011111 1010000 1011111 1011011

0 commit comments

Comments
 (0)
Please sign in to comment.