-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpaceAge.hs
More file actions
42 lines (36 loc) · 1.53 KB
/
SpaceAge.hs
File metadata and controls
42 lines (36 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module SpaceAge (Planet(..), ageOn) where
import Data.List
--Given an age in seconds, calculate how old someone would be on:
--Mercury: orbital period 0.2408467 Earth years
--Venus: orbital period 0.61519726 Earth years
--Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds
--Mars: orbital period 1.8808158 Earth years
--Jupiter: orbital period 11.862615 Earth years
--Saturn: orbital period 29.447498 Earth years
--Uranus: orbital period 84.016846 Earth years
--Neptune: orbital period 164.79132 Earth years
--So if you were told someone were 1,000,000,000 seconds old, you should be able to say that they're 31.69 Earth-years old.
data Planet = Mercury
| Venus
| Earth
| Mars
| Jupiter
| Saturn
| Uranus
| Neptune
type Planets = [(Planet, Float)]
orbPers :: Planets
orbPers = [(Mercury, 0.2408467), (Venus, 0.61519726), (Earth, 1), (Mars, 1.8808158)]
ageOn :: Planet -> Float -> Float
ageOn p a = snd (head ((filter (p == fst) orbPers)))
--orbPer :: Planet -> Float
--orbPer
-- | Mercury = 0.2408467
--ageOn Mercury seconds = ageOn Earth seconds / 0.2408467
--ageOn Venus seconds = ageOn Earth seconds / 0.61519726
--ageOn Earth seconds= seconds / 31557600
--ageOn Mars seconds = ageOn Earth seconds / 1.8808158
--ageOn Jupiter seconds = ageOn Earth seconds / 11.862615
--ageOn Saturn seconds = ageOn Earth seconds / 29.447498
--ageOn Uranus seconds = ageOn Earth seconds / 84.016846
--ageOn Neptune seconds = ageOn Earth seconds / 164.79132