-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up some extraneous idents that could easily be closures
- Loading branch information
Showing
9 changed files
with
121 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,28 @@ | ||
use rayon::prelude::*; | ||
use serde_json::Value; | ||
|
||
use crate::types::{problem, Problem}; | ||
|
||
pub const JS_ABACUS_FRAMEWORK_DOT_IO: Problem = problem!( | ||
|input| serde_json::from_str(input).map(|root| sum_numbers(root, false)), | ||
|input| serde_json::from_str(input).map(|root| sum_numbers(root, true)) | ||
); | ||
|
||
fn sum_numbers(value: Value, ignore_red: bool) -> i64 { | ||
match value { | ||
Value::Null => 0, | ||
Value::Bool(_) => 0, | ||
Value::Number(number) => number.as_i64().expect("number to be an integer"), | ||
Value::String(_) => 0, | ||
Value::Array(vec) => vec | ||
.into_par_iter() | ||
.map(|val| sum_numbers(val, ignore_red)) | ||
.sum(), | ||
Value::Object(map) if ignore_red && map.values().any(|val| val == "red") => 0, | ||
Value::Object(map) => map | ||
.into_iter() | ||
.par_bridge() | ||
.map(|(_, value)| sum_numbers(value, ignore_red)) | ||
.sum(), | ||
} | ||
} |
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