-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
475e0c6
commit 7f38f61
Showing
3 changed files
with
42 additions
and
1 deletion.
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
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
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,20 @@ | ||
//! Find the median of a collection of numbers. | ||
//! | ||
//! Of course, we are asking our good friend, the host, for help, but we still need to verify the answer. | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate ceno_rt; | ||
use ceno_rt::println; | ||
use core::fmt::Write; | ||
use rkyv::{Archived, vec::ArchivedVec}; | ||
|
||
ceno_rt::entry!(main); | ||
fn main() { | ||
let numbers: &ArchivedVec<u32> = ceno_rt::read(); | ||
let median_candidate: &Archived<u32> = ceno_rt::read(); | ||
let median_candidate = &&median_candidate.to_native(); | ||
let smaller = numbers.into_iter().filter(move |x| x < median_candidate).count(); | ||
assert_eq!(smaller, numbers.len() / 2); | ||
println!("{}", median_candidate); | ||
} |