The elves were in high spirits. For the first time in centuries, yesterday’s code review had eradicated every unnecessary heap allocation in Santa’s list-checking algorithm. “Finally,” yapped an elf sipping a Red Bull mocktail, “no more unnecessary allocations, no more clones”
The workshop buzzed with excitement as the DevOps elves live-streamed the successful merge on ElfHub. Even Blitzen was chill for once, reclining by the server rack, listening to lofi beats.
But the joy didn’t last.
Santa stormed in, his energy somewhere between a VC pitch gone wrong and a meme that didn’t land on X. His face was redder than Rudolph’s nose.
“WHY,” he roared, “IS THE NICE LIST COMPLETELY EMPTY?”
The elves froze.
“What do you mean, empty?” stammered an elf. “It compiled perfectly last night—”
Santa cut them off. “LOOK! Not a single kid on the Nice list. Did you break the weights? Are we back to random clones and allocations?!” He slammed his candy-cane laptop onto the nearest desk, the screen glaring with the issue.
The elves scrambled to debug. An intrepid junior elf opened the codebase. “Wait,” they muttered. “The weights are fine, but... the ratio logic’s busted.”
They pointed at the critical function, it was written in Python and didn't look so good.
"Anyone want to debug?" Santa added, his voice a mix of hope and despair. Surprisingly, nobody answered, it seemed like the code was written so badly that nobody wanted to touch it.
"Forget it," Santa said, "We'll re-write everything in Rust. I heard it's the new trend."
Help the elves re-write the is_nice
function in Rust. Santa needs the Nice list back before Christmas Eve.
The is_nice
function accepts two arguments:
good_deeds: u32
: The number of good deeds a kid has done.bad_deeds: u32
: The number of bad deeds a kid has done.To calculate the ratio, follow this logic:
Bad deeds are weighted more heavily than good deeds (twice as much). So, the final ratio is calculated as:
After you find the ratio, you'll need to check if the kid is nice. A kid is considered nice if the ratio is greater than or equal to 0.75
, if nice return true
, otherwise return false
.
Santa’s counting on you. Save Christmas and keep the Nice list free of data breaches — and, hopefully, Santa himself.
good_deeds
and bad_deeds
are 0
, the kid is naughty by default.bool
value.If you're stuck, here are some hints to help you get back on track:
Use the as
keywords to convert the u32
(unsigned 32-bit integer) to a f64
(floating-point number) before doing any numerical operations. e.g. good_deeds as f64
Remember to use parentheses to ensure the correct order of operations.
Remember to return a bool
value from the function.
sukman
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false } let ratio = (good_deeds as f32 * GOOD_WEIGHT) / ((good_deeds as f32 * GOOD_WEIGHT) + (bad_deeds as f32 * BAD_WEIGHT)); ratio >= 0.75}
admiraladmirable
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub const GOOD_ENOUGH: f32 = 0.75;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if (good_deeds as f32 * GOOD_WEIGHT) / ((good_deeds as f32 * GOOD_WEIGHT) + (bad_deeds as f32 * BAD_WEIGHT)) >= GOOD_ENOUGH { true } else { false }}
SchnobiTobi
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 {return false} good_deeds as f32 / (good_deeds + (2 * bad_deeds)) as f32 >= 0.75}
Ruspoetin
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if (0, 0) == (good_deeds, bad_deeds) { return false } let ratio: f32 = (good_deeds as f32 * GOOD_WEIGHT) / (good_deeds as f32 * GOOD_WEIGHT + bad_deeds as f32 * BAD_WEIGHT); let limit: f32 = 0.75; if ratio >= limit { return true; } else { return false; }}
ohorn
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let weigthed_good_deeds = good_deeds as f32 * GOOD_WEIGHT; let weigthed_bad_deeds = bad_deeds as f32 * BAD_WEIGHT; weigthed_good_deeds / (weigthed_good_deeds + weigthed_bad_deeds) >= 0.75}
recursivemaze
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false } else { let ratio = GOOD_WEIGHT * good_deeds as f32 / (GOOD_WEIGHT * good_deeds as f32 + (BAD_WEIGHT * bad_deeds as f32)); if ratio >= 0.75 {return true} else {return false}};}
StephaneTrebel
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let gd = good_deeds as f32 * GOOD_WEIGHT; let bd = bad_deeds as f32 * BAD_WEIGHT; if gd == 0.0 && bd == 0.0 { return false; } if bd == 0.0 { return true } return (gd / (gd + bd)) >= 0.75}
py-chemist
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false } let ratio = good_deeds as f32 / (good_deeds as f32 + (bad_deeds as f32 * BAD_WEIGHT)); if ratio >= 0.75 { true } else { false }}
fieldgm6
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 points// Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughtypub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false } else { let ratio = GOOD_WEIGHT * good_deeds as f32 / (GOOD_WEIGHT * good_deeds as f32 + (BAD_WEIGHT * bad_deeds as f32)); if ratio >= 0.75 {return true} else {return false}};}
markuswege
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false; } let ratio = good_deeds as f32 / (good_deeds as f32 * GOOD_WEIGHT + bad_deeds as f32 * BAD_WEIGHT); if ratio < 0.75{ return false; } true}
c4s4
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false }; let ratio = (good_deeds as f32 * GOOD_WEIGHT) / ((good_deeds as f32 * GOOD_WEIGHT) + (bad_deeds as f32 * BAD_WEIGHT)); return ratio >= 0.75;}
IvanyaK
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { let ratio: f32 = good_deeds as f32 / (good_deeds as f32 + (2.0 * bad_deeds as f32)); if ratio >= 0.75 { true } else { false }}
alankle
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false; }; let good_deeds: f32 = good_deeds as f32; let bad_deeds: f32 = bad_deeds as f32; let ratio: f32 = good_deeds / (good_deeds + (2.0 * bad_deeds )); if ratio >= 0.75 { return true; } else { return false; };}
LenRemmerswaal
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let good = (good_deeds as f32 * GOOD_WEIGHT); good/(good + bad_deeds as f32 * BAD_WEIGHT) >= 0.75}
gkapkowski-saucelabs
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false; } let ratio = good_deeds as f64 / (good_deeds as f64 + 2.0 as f64 * bad_deeds as f64); return ratio >= 0.75;}
kj-9
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false }; return 0.75 <= (good_deeds as f32 / (good_deeds as f32 + (2 * bad_deeds) as f32))}
kj-9
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false } else { let ratio = GOOD_WEIGHT * good_deeds as f32 / ( GOOD_WEIGHT *good_deeds as f32 + (BAD_WEIGHT * bad_deeds as f32)); if ratio >= 0.75 { return true } else { return false }; };}
rawar089
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false; } let good = GOOD_WEIGHT as f64 * good_deeds as f64; let bad = BAD_WEIGHT as f64 * bad_deeds as f64; if (good / (good + bad)) >= 0.75 { true } else { false }}
zealsham
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f64 = 1.0;pub const BAD_WEIGHT: f64 = 2.0;pub fn is_nice(good_deeds: u64, bad_deeds: u64) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughtif good_deeds == 0 && bad_deeds == 0 { return false; } let total_weighted_deeds = (GOOD_WEIGHT * good_deeds as f64) + (BAD_WEIGHT * bad_deeds as f64); let ratio = (GOOD_WEIGHT * good_deeds as f64) / total_weighted_deeds; ratio >= 0.7}
doeixd
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if (good_deeds <= 0) { return false }; if (bad_deeds <= 0) { return true }; let good_deeds: f32 = (good_deeds as f32) * GOOD_WEIGHT; let bad_deeds: f32 = (bad_deeds as f32) * BAD_WEIGHT; let ratio: f32 = (good_deeds / (good_deeds + (bad_deeds))) as f32; match ratio { r if r >=0.75 => true, _ => false } // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty}
dasunpubudumal
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds: f32 = good_deeds as f32; let bad_deeds: f32 = bad_deeds as f32; let good_ratio: f32 = (GOOD_WEIGHT * good_deeds) / ((GOOD_WEIGHT * good_deeds) + (BAD_WEIGHT * bad_deeds)); if good_ratio >= 0.75 { return true; } false}
midnightexigent
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let ratio = good_deeds as f32 / (good_deeds as f32 + (BAD_WEIGHT * bad_deeds as f32)); ratio >= 0.75}
sgt
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty (good_deeds as f32 * GOOD_WEIGHT / (good_deeds as f32 * GOOD_WEIGHT + bad_deeds as f32 * BAD_WEIGHT)) >= 0.75}
AviAvni
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty (good_deeds as f32 / (good_deeds + (2 * bad_deeds)) as f32) >= 0.75}
var4yn
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty // 75 / 100 0.75 <= good_deeds as f32 / ( GOOD_WEIGHT * ( good_deeds as f32 ) + (bad_deeds as f32) * BAD_WEIGHT )}
mrsalo
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { match (good_deeds, bad_deeds) { (0, 0) => { false } (g, b) => { g as f64 / (g as f64 + 2_f64 * b as f64) >= 0.75 } } }
dalprahcd
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty bad_deeds + good_deeds > 0 && good_deeds * 4 >= 3 * (good_deeds + 2 * bad_deeds)}
WuHan0608
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty (good_deeds as f64) / ((good_deeds + 2 * bad_deeds) as f64) >= 0.75}
emakryo
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { false } else { good_deeds as f64 / (good_deeds + 2 * bad_deeds) as f64 >= 0.75 }}
theandi667
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds + bad_deeds == 0 { return false; } let good_deeds = (good_deeds as f32) * GOOD_WEIGHT; let bad_deeds = (bad_deeds as f32) * BAD_WEIGHT; let ratio = good_deeds / (good_deeds + bad_deeds); ratio >= 0.75}
jeffglaum
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let ratio = good_deeds as f32 / (good_deeds as f32 + (2.0 * bad_deeds as f32)); if ratio >= 0.75 { true } else { false }}
plauche
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let good_deeds_f = good_deeds as f32; let bad_deeds_f = (bad_deeds * 2) as f32; let ratio = good_deeds_f / (good_deeds_f + bad_deeds_f); if ratio >= 0.75 { true } else { false }}
0xkuznechik
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } good_deeds as f32 * GOOD_WEIGHT / (good_deeds as f32 * GOOD_WEIGHT + bad_deeds as f32 * BAD_WEIGHT) >= 0.75 // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty}
jon-a-miller
pub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_deeds = good_deeds as f32; let bad_deeds = bad_deeds as f32; let ratio: f32 = good_deeds * GOOD_WEIGHT / (good_deeds + (BAD_WEIGHT * bad_deeds)); ratio >= 0.75 }
nikwi
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { bad_deeds + good_deeds > 0 && good_deeds * 4 >= 3 * (good_deeds + 2 * bad_deeds)}
dpathakj
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { let ratio = good_deeds as f32 * GOOD_WEIGHT / (good_deeds as f32 * GOOD_WEIGHT + (bad_deeds as f32 * BAD_WEIGHT)); ratio >= 0.75 // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty}
Kada-quantum
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) let ratio = GOOD_WEIGHT*good_deeds as f32 / (GOOD_WEIGHT*good_deeds as f32 + BAD_WEIGHT*bad_deeds as f32); // If both good and bad deeds are 0, the child is naughty ratio >= 0.75}
vabka
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_score = good_deeds as f32 * GOOD_WEIGHT; let bad_score = bad_deeds as f32 * BAD_WEIGHT; (good_score / (good_score + bad_score)) >= 0.75}
vabka
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { return false; } let good_score = good_deeds as f32 * GOOD_WEIGHT; let bad_score = bad_deeds as f32 * BAD_WEIGHT; (good_score / (good_score + bad_score)) >= 0.75}
jpekmez
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds == 0 && bad_deeds == 0 { return false } let good_deeds = good_deeds as f64; let bad_deeds = bad_deeds as f64; good_deeds / (good_deeds + (bad_deeds * 2f64)) >= 0.75f64}
tuusberg
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f64 = 1.0;pub const BAD_WEIGHT: f64 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { println!("{}", good_deeds); println!("{}", bad_deeds); let good_total = good_deeds as f64 * GOOD_WEIGHT; let bad_total = bad_deeds as f64 * BAD_WEIGHT; return good_total / (good_total + bad_total) >= 0.75}
m0nkey653
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if bad_deeds == 0 && good_deeds == 0 { return false; } if bad_deeds == 0 { return true; } let good_deed_weighted = good_deeds as f64 * GOOD_WEIGHT as f64; let bad_deed_weighted = bad_deeds as f64 * BAD_WEIGHT as f64; return (good_deed_weighted / (good_deed_weighted + (bad_deed_weighted))) >= 0.75;}
edgarcnp
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let bad_deeds_ratio: f32 = bad_deeds as f32 * BAD_WEIGHT; let good_deeds_ratio: f32 = good_deeds as f32 * GOOD_WEIGHT; let final_ratio: f32 = (good_deeds_ratio) / (good_deeds_ratio + bad_deeds_ratio); if good_deeds_ratio == 0.0 && bad_deeds_ratio == 0.0 { return false; } final_ratio >= 0.75}
maplestarplayl
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if (good_deeds == 0 && bad_deeds == 0) { return false; } let ratio = good_deeds as f32 * GOOD_WEIGHT / (good_deeds as f32 * GOOD_WEIGHT + BAD_WEIGHT * bad_deeds as f32) ; return match ratio { 0.7..=1.0 => true, _ => false, };}
yuankunzhang
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub const THRESHOLD: f32 = 0.75;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { if good_deeds == 0 && bad_deeds == 0 { false } else { good_deeds as f32 / (good_deeds as f32 * GOOD_WEIGHT + bad_deeds as f32 * BAD_WEIGHT) >= THRESHOLD } // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty}
rostyq
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty let good_score = GOOD_WEIGHT * good_deeds as f32; let bad_score = BAD_WEIGHT * bad_deeds as f32; let ratio = good_score / (good_score + bad_score); ratio >= 0.75}
raisiope
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty if good_deeds != 0 || bad_deeds != 0 { let good = good_deeds as f32 * GOOD_WEIGHT; let bad = bad_deeds as f32 * BAD_WEIGHT; let nice = good / (good + bad); nice >= 0.75f32 } else { false } }
filippodebortoli
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { let good: f32 = (good_deeds as f32) * GOOD_WEIGHT; let bad: f32 = (bad_deeds as f32) * BAD_WEIGHT; (good_deeds != 0 || bad_deeds != 0) && (good / (bad + good) >= 0.75) // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty}
mEstrazulas
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naughty good_deeds as f32 * GOOD_WEIGHT / ((good_deeds as f32 * GOOD_WEIGHT) + (bad_deeds as f32 * BAD_WEIGHT)) >= 0.75}
ekreutz
// We need to find the nice and naughty kids for santa// Each good deed is worth 1 point and each bad deed is worth 2 pointspub const GOOD_WEIGHT: f32 = 1.0;pub const BAD_WEIGHT: f32 = 2.0;pub fn is_nice(good_deeds: u32, bad_deeds: u32) -> bool { // Calculate the ratio of good deeds to total deeds // Any ratio greater than or equal to 0.75 is considered nice // e.g. 10 good deeds and 2 bad deeds = // (10 * 1) / ((10 * 1) + (2 * 2)) = 10 / 14 = 0.714... (not nice) // If both good and bad deeds are 0, the child is naught let good_f: f32 = good_deeds as f32 * GOOD_WEIGHT; let bad_f: f32 = bad_deeds as f32 * BAD_WEIGHT; let total_deeds: f32 = good_f + bad_f; total_deeds > 0.0 && good_f / total_deeds >= 0.75}