Sha256: c26667c85c304125089b519d9b65f2c8581bcc4d6a222dad100c50b7da5970eb

Contents?: true

Size: 595 Bytes

Versions: 134

Compression:

Stored size: 595 Bytes

Contents

fun decimal n = let
    val digits = List.map (fn c => (ord c) - 48) (explode n)
    val len = List.length digits

    fun validate []      = true
      | validate (d::ds) = if d <> 0 andalso d <> 1 then false
                           else validate ds
    fun even n = (n mod 2) = 0
    fun int_pow a b = Real.toInt IEEEReal.TO_NEAREST (Math.pow (Real.fromInt(a), Real.fromInt(b)))
    fun f' []      mult acc = acc
      | f' (x::xs) mult acc = f' xs (mult - 1) (acc + (x * (int_pow 2 mult)))
in
    if len = 0 orelse not(validate digits) then NONE
    else SOME (f' digits (len - 1) 0)
end

Version data entries

134 entries across 134 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.179 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.178 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.177 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.176 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.175 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.174 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.173 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.172 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.171 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.170 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.169 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.167 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.166 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.165 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.164 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.163 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.162 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.161 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.160 tracks/sml/exercises/binary/example.sml