restructure; add challenge 2 solution
I forgot about atomic commits...
This commit is contained in:
parent
85a7ee0b8e
commit
bfb7d95aa7
10 changed files with 207 additions and 64 deletions
7
challenges/december-2024/c1/Cargo.lock
generated
Normal file
7
challenges/december-2024/c1/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "frzn-challenge"
|
||||
version = "0.1.0"
|
||||
9
challenges/december-2024/c1/Cargo.toml
Normal file
9
challenges/december-2024/c1/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "challenge-1"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
geometry = {path = "../../../lib/geometry" }
|
||||
|
||||
|
||||
28
challenges/december-2024/c1/src/main.rs
Normal file
28
challenges/december-2024/c1/src/main.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use geometry::{read_point, Triangle};
|
||||
fn main() {
|
||||
// Read the vertices of the triangle we are calculating the area for.
|
||||
let p1 = read_point("Enter the coordinates for the first vertex of the triangle (x y):");
|
||||
let p2 = read_point("Enter the coordinates for the second vertex of the triangle (x y):");
|
||||
let p3 = read_point("Enter the coordinates for the third vertex of the triangle (x y):");
|
||||
|
||||
// 'Draw' the triangle.
|
||||
let triangle = Triangle { p1, p2, p3 };
|
||||
|
||||
// Read the point we want to test from user input.
|
||||
// TODO: maybe some kind of input validation/loop would be nice
|
||||
let test_point = read_point("Enter the coordinates for the point to test (x y):");
|
||||
|
||||
// Finally, check if the point is inside the triangle.
|
||||
// TODO: make this a match
|
||||
if triangle.contains_point(&test_point) {
|
||||
println!(
|
||||
"The point ({}, {}) lies inside the triangle.",
|
||||
test_point.x, test_point.y
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"The point ({}, {}) lies outside the triangle.",
|
||||
test_point.x, test_point.y
|
||||
);
|
||||
}
|
||||
}
|
||||
9
challenges/december-2024/c2/Cargo.toml
Normal file
9
challenges/december-2024/c2/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "challenge-2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
geometry = {path = "../../../lib/geometry" }
|
||||
|
||||
|
||||
24
challenges/december-2024/c2/src/main.rs
Normal file
24
challenges/december-2024/c2/src/main.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use geometry::{read_point, Triangle};
|
||||
|
||||
fn read_triangle(name: &str) -> Triangle {
|
||||
println!(
|
||||
"Enter the coordinates for the three vertices of triangle {}:",
|
||||
name
|
||||
);
|
||||
let p1 = read_point("First vertex (x y):");
|
||||
let p2 = read_point("Second vertex (x y):");
|
||||
let p3 = read_point("Third vertex (x y):");
|
||||
|
||||
Triangle { p1, p2, p3 }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let triangle1 = read_triangle("1");
|
||||
let triangle2 = read_triangle("2");
|
||||
|
||||
if triangle1.overlaps(&triangle2) {
|
||||
println!("The two triangles overlap.");
|
||||
} else {
|
||||
println!("The two triangles do not overlap.");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue