Coding challenge ( rust)

Give it a try and see if you can predict the output of this Rust program.
use std::collections::HashMap;

fn main() {
let input_numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

let result: Vec<_> = input_numbers
.iter()
.filter(|&&x| x % 2 == 0)
.map(|x| x * x)
.filter(|&x| x > 20)
.fold(HashMap::new(), |mut acc, x| {
let counter = acc.entry(x % 5).or_insert(0);
*counter += 1;
acc
})
.into_iter()
.filter(|&(_, count)| count > 1)
.map(|(key, _)| key)
.collect();

println!("{:?}", result);
}
use std::collections::HashMap;

fn main() {
let input_numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

let result: Vec<_> = input_numbers
.iter()
.filter(|&&x| x % 2 == 0)
.map(|x| x * x)
.filter(|&x| x > 20)
.fold(HashMap::new(), |mut acc, x| {
let counter = acc.entry(x % 5).or_insert(0);
*counter += 1;
acc
})
.into_iter()
.filter(|&(_, count)| count > 1)
.map(|(key, _)| key)
.collect();

println!("{:?}", result);
}
4 Replies
Aditya thakekar
Aditya thakekar4mo ago
Feels like something is missing
nour_oud
nour_oud4mo ago
Nope, just a trap 😆
Aditya thakekar
Aditya thakekar4mo ago
Empty array 😏😏😏
nour_oud
nour_oud4mo ago
Yup 🙌 , what about the steps ?
Want results from more Discord servers?
Add your server
More Posts
Testonica's Quick Instruments Test framework for quality controlhttps://www.testonica.com/products/qi One of the marketing guys from here reached out to me and I fWearPico - Open-source Smartwatch firmware written in C for the Raspberry Pi PicoThe WearPico is an open-source smartwatch project developed by a maker and developer utilizing the RZero Ohms resistor on the Power LineAm designing a PCB Board, in the schematics section at the power line, I added a Zero ohms resistor DEVHEADS DEMO: How to Implement Finite State Machines in FPGA FabricFPGAs are among the most versatile technologies available on the market today, but capitalizing on tAchronix's FPGA Solutions for Generative AIhttps://insidehpc.com/2023/12/at-sc23-achronix-talks-turnkey-fpga-solutions-for-generative-ai/ httpFrom C++ to Rust: Comparison from Embedded Software EngineerIn this captivating article, an experienced embedded software engineer delves into a comprehensive chow to port lvgl to the plaftformio (esp-idf framework)Hi everyone, I’m currently encountering a challenge in determining whether I am on the right way porNeed help making the shift from bare-metal to RTOSSo I'm navigating the transition from a bare-metal setup to utilizing an RTOS for my embedded projecAn Introduction to Flyback Converters: Parameters, Topology, and Controllershttps://www.monolithicpower.com/en/an-introduction-to-flyback-converters-parameters-topology-and-conWiFiManager Integration in ESP32Hi all, I have an ESP32 receiving information from another ESP32 equipped with sensors. Below is the