Search
 
SCRIPT & CODE EXAMPLE
 

RUST

Project Euler #1 Multiples of 3 or 5

// Project Euler #1 Multiples of 3 or 5
// num is the maximum number e.g. 1000
// Iterative
fn solution(num: i32) -> i32 {
    let mut sum = 0;
    for i in 1 .. num {
        if i % 3 == 0 || i % 5 == 0 {
            sum += i;
        }
    }
    sum
}

// Using filter
fn solution(num: i32) -> i32 {
  (1..num).filter(|x| x % 3 == 0 || x % 5 == 0 ).sum()
}
Comment

PREVIOUS NEXT
Code Example
Rust :: rust comment types 
Rust :: rust function 
Rust :: error handling rust 
Rust :: rust lang enum 
Rust :: rust•armanriazi•concept•semantic 
Rust :: rust•armanriazi•osstring•vs•path 
Rust :: get function name rust 
Rust :: sort_by in rust 
Rust :: armanriazi•rust•unsafe•comparison•references•smartpointers•rawpointer 
Rust :: armanriazi•rust•mem•deallocating 
Rust :: armanriazi•rust•error•[E0782]: trait objects must include the `dyn` keyword 
Rust :: rust•armanriazi•cast•try_into•unwrap 
Rust :: armanriazi•rust•thread•multi•arc•mutex 
Rust :: armanriazi•rust•concept•pattern•newtype 
Rust :: primitive data types in rust 
Lua :: random string generator lua 
Lua :: clickdetector player roblox 
Lua :: roblox make kill brick 
Lua :: luau loop players 
Lua :: how to exit current scope roblox 
Lua :: roblox how to get the players mouse 
Lua :: roblox math.random 
Lua :: lua len array 
Lua :: lua push to aray 
Lua :: svelte template vite 
Lua :: lua roblox hack scripts 
Lua :: roblox for loop 
Matlab :: streamline matlab 
Matlab :: matlab select element of matrix 
Basic :: virtualbox 256 vram 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =