← Back to archive

Stdle #144 · option · 2026-10-28

What does this Rust snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

fn main() {
let x: Option<i32> = Some(5);
let r = x.map(|n| n + 1).unwrap_or(0);
println!("{}", r);
let y: Option<i32> = None;
println!("{}", y.map(|n| n + 1).unwrap_or(0));
}
Option
2 lines
4 attempts left

Answer & explanation