Initial commit
This commit is contained in:
1
Rust/code_cycle/.gitignore
vendored
Normal file
1
Rust/code_cycle/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
7
Rust/code_cycle/Cargo.lock
generated
Normal file
7
Rust/code_cycle/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "code_cycle"
|
||||
version = "0.1.0"
|
||||
19
Rust/code_cycle/Cargo.toml
Normal file
19
Rust/code_cycle/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "code_cycle"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.dev.package."*"] # +
|
||||
opt-level = "z" # Optimize library for size
|
||||
|
||||
[profile.release]
|
||||
#opt-level = 'z' # Optimize for size
|
||||
opt-level = 3 # Optimize for speed
|
||||
lto = true # Enable link-time optimization
|
||||
codegen-units = 1 # Reduce number of codegen units to increase optimizations
|
||||
panic = 'abort' # Abort on panic
|
||||
strip = true # Strip symbols from binary*
|
||||
|
||||
[dependencies]
|
||||
18
Rust/code_cycle/src/main.rs
Normal file
18
Rust/code_cycle/src/main.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
fn main() {
|
||||
let total_attempts: i32 = 256*256*256;
|
||||
let mut successful_attempts: i32 = 0;
|
||||
|
||||
for a in 0..256 {
|
||||
for b in 0..256 {
|
||||
for c in 0..256 {
|
||||
if a + b + c > 300 {
|
||||
successful_attempts += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("Iterations: {}", total_attempts);
|
||||
println!("Valid sums: {}", successful_attempts);
|
||||
println!("Probability: {}", successful_attempts as f32 / total_attempts as f32);
|
||||
}
|
||||
Reference in New Issue
Block a user