Skip to content

Commit 2b04411

Browse files
authored
Merge pull request kelvins#71 from heitor582/main
[rust] adiciona extra Calculo do PI (Leibniz)
2 parents a024f0c + 586598c commit 2b04411

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
7070
| Soma de 2 Números | C/C++ | Java | [Python](./src/python/soma_dois_numeros.py) | Go | Ruby | JS | Pascal | Swift | Rust |
7171
| [Palíndromo][49] | [C/C++](./src/c/Palindromo.c) | Java | Python | Go | [Ruby](./src/ruby/Palindromo.rb) | [JS](./src/javascript/Palindromo.js) | Pascal | [Swift](./src/swift/palindromo.swift) | [Rust](./src/rust/palindromo.rs) |
7272
| Lista Ligada Desordenada | C/C++ | Java | [Python](./src/python/lista_encadeada_desordenada.py) | Go | Ruby | JS | Pascal | Swift | Rust |
73-
| [Calculo do PI (Leibniz)][50] | C/C++ | Java | [Python](./src/python/calculate_pi.py) | [Go](./src/go/calculatepi/calculatepi.go) | Ruby | [JS](./src/javascript/calculate_pi.js) | Pascal | Swift | Rust |
73+
| [Calculo do PI (Leibniz)][50] | C/C++ | Java | [Python](./src/python/calculate_pi.py) | [Go](./src/go/calculatepi/calculatepi.go) | Ruby | [JS](./src/javascript/calculate_pi.js) | Pascal | Swift | [Rust](./src/rust/calculate_pi.rs) |
7474
| Busca em Labirinto | C/C++ | Java | [Python](./src/python/busca_em_labirinto.py) | Go | Ruby | JS | Pascal | Swift | Rust |
7575

7676
## :ferris_wheel: Playgrounds

src/rust/calculate_pi.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fn main(){
2+
println!("{:?}", calculate_pi(vec![10, 1000, 100000, 10000000]));
3+
}
4+
fn calculate_pi(terms: Vec<i32>) -> Vec<f64> {
5+
let mut denominator: f64;
6+
let mut operation: f64;
7+
let mut pi: Vec<f64> = Vec::<f64>::new();
8+
9+
for i in 0..terms.len() {
10+
denominator = 1.0;
11+
operation = 1.0;
12+
pi.push(0.0);
13+
for _ in 0..terms[i] {
14+
let i: usize = i as usize;
15+
pi[i] += operation * (4.0 / denominator);
16+
denominator += 2.0;
17+
operation *= -1.0;
18+
}
19+
}
20+
pi
21+
}

0 commit comments

Comments
 (0)