-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod p05; | ||
mod p06; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#[test] | ||
fn test20() { | ||
const W: u32 = 10; | ||
const H: u32 = 10; | ||
|
||
for y in 0..H { | ||
for x in 0..W { | ||
let c = if y == 0 || y == H - 1 || x == 0 || x == W - 1 || x == y || x == H - 1 - y { | ||
'*' | ||
} else { | ||
' ' | ||
}; | ||
print!("{}", c); | ||
} | ||
println!(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test21() { | ||
const W: u32 = 10; | ||
const H: u32 = 10; | ||
|
||
for y in 0..H { | ||
for x in 0..W { | ||
let is_horizontal = y == 0 || y == H - 1; | ||
let is_vertical = x == 0 || x == W - 1; | ||
let id_diagonal = x == y; | ||
let id_co_diagonal = x == W - 1 - y; | ||
|
||
let c = if is_horizontal || is_vertical || id_diagonal || id_co_diagonal { | ||
'*' | ||
} else { | ||
' ' | ||
}; | ||
print!("{}", c); | ||
} | ||
println!(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test22() { | ||
const W: u32 = 25; | ||
const H: u32 = 10; | ||
let k = W / H; // 2 | ||
|
||
for y in 0..H { | ||
for x in 0..W { | ||
let is_horizontal = y == 0 || y == H - 1; | ||
let is_vertical = x == 0 || x == W - 1; | ||
let id_diagonal = x == y * k; | ||
let id_co_diagonal = x == W - 1 - y * k; | ||
|
||
let c = if is_horizontal || is_vertical || id_diagonal || id_co_diagonal { | ||
'*' | ||
} else { | ||
' ' | ||
}; | ||
print!("{}", c); | ||
} | ||
println!(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test23() { | ||
const W: u32 = 25; | ||
const H: u32 = 10; | ||
let k = W as f32 / H as f32; // 2.5 | ||
|
||
for y in 0..H { | ||
for x in 0..W { | ||
let is_horizontal = y == 0 || y == H - 1; | ||
let is_vertical = x == 0 || x == W - 1; | ||
let id_diagonal = x == (y as f32 * k) as u32; | ||
let id_co_diagonal = x == W - 1 - (y as f32 * k) as u32; | ||
|
||
let c = if is_horizontal || is_vertical || id_diagonal || id_co_diagonal { | ||
'*' | ||
} else { | ||
' ' | ||
}; | ||
print!("{}", c); | ||
} | ||
println!(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test24() { | ||
const W: u32 = 25; | ||
const H: u32 = 10; | ||
let k = W as f32 / H as f32; // 2.5 | ||
|
||
fn mul(a: u32, b: f32) -> u32 { | ||
(a as f32 * b) as u32 | ||
} | ||
|
||
for y in 1..=H { | ||
for x in 1..=W { | ||
let c: char = match (x, y) { | ||
(_, 1 | H) => '-', | ||
(1 | W, _) => '|', | ||
_ if x == mul(y, k) => '\\', | ||
_ if x == W - mul(y, k) => '/', | ||
_ => ' ', | ||
}; | ||
print!("{}", c); | ||
} | ||
println!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod envelope; |
Binary file not shown.