Skip to content

Margus Roo –

If you're inventing and pioneering, you have to be willing to be misunderstood for long periods of time

  • Cloudbreak Autoscale fix
  • Endast

Haskell – beauty of couding – get perfect numbers

Posted on January 11, 2015 - January 11, 2015 by margusja

Recently did some haskell coding and just some lines to explain my enthusiasm.

Let’s try to calculate  perfect numbers:

First I have helper function factors to get number factors:

factors :: Int -> [Int]
factors a = [ x | x <- [1..a], y <- [1..a], x*y == a ]

and the main function is:

perfects :: Int -> [Int]
perfects x = [a | a <- [1..x], sum (init(factors a)) == a, a <= x]

to get perfect numbers under limit believe me you want to limit the calculation 🙂

Posted in IT

Post navigation

Apache-PIG how to save output into different places
One of the best explanation about bitwise operators

The Master

Categories

  • Apache
  • Apple
  • Assembler
  • Audi
  • BigData
  • BMW
  • C
  • Elektroonika
  • Fun
  • Hadoop
  • help
  • Infotehnoloogia koolis
  • IOT
  • IT
  • IT eetilised
  • Java
  • Langevarjundus
  • Lapsed
  • lastekodu
  • Linux
  • M-401
  • Mac
  • Machine Learning
  • Matemaatika
  • Math
  • MSP430
  • Muusika
  • neo4j
  • openCL
  • Õpetaja identiteet ja tegevusvõimekus
  • oracle
  • PHP
  • PostgreSql
  • ProM
  • R
  • Turvalisus
  • Varia
  • Windows
Proudly powered by WordPress | Theme: micro, developed by DevriX.