DEV Community

My Solutions for Perfect Number in Several Languages

chenge on November 15, 2018

There's a warm discuss in post Write a script to find "Perfect Numbers" . Here's my solutions. Ruby def sum_divisions(n) (1...n).select{|i| n ...
Collapse
 
grayjack profile image
GrayJack • Edited

In rust, there 2 idiomatic way to do the main()

Your version is idiomatic, but there also this way:

fn main(){
  (1..10_000).filter(|x| is_perfect(*x)).for_each(|x| println!("{}", x));
}

For something simple like this, I would use this version

Collapse
 
chenge profile image
chenge

This is like Ruby, nice.

Collapse
 
jcsvveiga profile image
João Veiga

In the Clojure example, you can move the if into :when clojuredocs.org/clojure.core/doseq...

Collapse
 
chenge profile image
chenge

thanks, that's better.