Skip to content

Instantly share code, notes, and snippets.

@AnthonyMikh
Created May 16, 2018 20:34
Show Gist options
  • Save AnthonyMikh/9187e02f827cea04b16c89834c15a691 to your computer and use it in GitHub Desktop.
Save AnthonyMikh/9187e02f827cea04b16c89834c15a691 to your computer and use it in GitHub Desktop.
Решение задачи №94 от UniLecs
type People = u32;
type Parts = People;
fn min_pie_parts(guests: People, old_friends: People) -> Parts {
fn gcd(a: People, b: People) -> People {
if a < b { gcd(b, a) }
else if b == 0 { a }
else { gcd(b, a % b) }
}
guests - gcd(guests, old_friends) + old_friends
}
#[test]
fn some_variants() {
assert_eq!(min_pie_parts(2, 3), 4);
assert_eq!(min_pie_parts(4, 8), 8);
assert_eq!(min_pie_parts(10, 15), 20);
}
@AnthonyMikh
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment