INDAPlus21 / INDAPlus21/murnion-task-2
Komplettering
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**Very well done Felix!**
However, you forgot to submit a screenshot for _Avstånd till kanten_. No worries; I submitted your solution, which got accepted.
Tips:
_Your code_:
```rust
fn main() {
// ...
for x in 1..=rows {
// ...
for y in 1..=columns {
name.push(dist_map(cmp::min(cmp::min(x, rows - x + 1), cmp::min(y, columns - y + 1))));
}
println!("{}", name);
}
}
fn dist_map(x: usize) -> char {
match x {
1 => '1',
2 => '2',
3 => '3',
4 => '4',
5 => '5',
6 => '6',
7 => '7',
8 => '8',
9 => '9',
_ => '.',
}
}
```
_Shorter code_:
```rust
fn main() {
// ...
for x in 1..=rows {
let mut name: String = String::with_capacity(columns);
for y in 1..=columns {
name.push(
match cmp::min(cmp::min(x, rows - x + 1), cmp::min(y, columns - y + 1)) {
_min if _min < 10 => std::char::from_digit(_min, 10).unwrap(),
_ => '.'
}
);
}
println!("{}", name);
}
}
```
_Optimised code_:
```rust
fn main() {
// ...
let mut name: String = String::with_capacity(columns);
for x in 1..=rows {
for y in 1..=columns {
name.push(
match cmp::min(cmp::min(x, rows - x + 1), cmp::min(y, columns - y + 1)) {
_min if _min < 10 => std::char::from_digit(_min, 10).unwrap(),
_ => '.'
}
);
}
println!("{}", &name);
name.clear(); // Reuse same string to avoid repeating memory allocation.
}
}
```
_More optimised code_:
```rust
fn main() {
// ...
for x in 1..=rows {
for y in 1..=columns {
// Print once per value to avoid heap allocation all together.
print!("{}",
match cmp::min(cmp::min(x, rows - x + 1), cmp::min(y, columns - y + 1)) {
_min if _min < 10 => std::char::from_digit(_min, 10).unwrap(),
_ => '.'
}
);
}
println!();
}
}
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is named. The issue describes an already accepted submission and provides Rust snippets, so confirm whether any follow-up is expected before changing anything; completion is unclear because no change is requested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 10/100