Last active
November 9, 2016 22:15
-
-
Save rhnasc/ae91ffebc3f6cbf044b0a637a231c435 to your computer and use it in GitHub Desktop.
Sorting an electrosphere with functional programming - elm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (text) | |
import Array | |
arr = | |
Array.fromList [ Array.fromList ["1s2"] | |
, Array.fromList ["2s2", "2p6"] | |
, Array.fromList ["3s2", "3p6", "3d10"] | |
, Array.fromList ["4s2", "4p6", "4d10", "4f14"] | |
, Array.fromList ["5s2", "5p6", "5d10", "5f14"] | |
, Array.fromList ["6s2", "6p6", "6d10"] | |
, Array.fromList ["7s2", "7p6"] | |
] | |
arr_i coords = | |
case coords of | |
(x,y) -> case Array.get x arr of | |
Just a -> case Array.get y a of | |
Just b -> b | |
Nothing -> "y out of bound" | |
Nothing -> "x out of bound" | |
next_iteration tuple = | |
case tuple of | |
(0,0) -> (1,0) | |
(x,0) -> (ceiling((x+1)/2),floor((x+1)/2)) | |
(x,y) -> (x+1,y-1) | |
iterations list = | |
case List.head list of | |
Just (6,1) -> list | |
Just tuple -> iterations[next_iteration tuple] ++ list | |
_ -> iterations [(0,0)] | |
main = text <| toString <| List.map arr_i ( List.reverse ( iterations [] ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment