Last active
February 24, 2024 07:38
-
-
Save convexbrain/668da800277bf608f4996961c75975af to your computer and use it in GitHub Desktop.
Optionでくるむと重くなる?? #rustlang
This file contains hidden or 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
use std::collections::BTreeSet; | |
fn func1(s: Option<BTreeSet<usize>>) -> BTreeSet<usize> { | |
let mut s = s.unwrap_or((0..100).collect()); | |
s.pop_first(); | |
s | |
} | |
fn func2(mut s: BTreeSet<usize>) -> BTreeSet<usize> { | |
s.pop_first(); | |
s | |
} | |
fn main() { | |
let mut args = std::env::args(); | |
args.next(); | |
let f: usize = args.next().unwrap().parse().unwrap(); | |
let n: usize = args.next().unwrap().parse().unwrap(); | |
let mut s: BTreeSet<usize> = (0..n).collect(); | |
while !s.is_empty() { | |
match f { | |
1 => { | |
s = func1(Some(s)); | |
}, | |
2 => { | |
s = func2(s); | |
}, | |
_ => { | |
panic!(); | |
}, | |
} | |
} | |
} |
Author
convexbrain
commented
Feb 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment