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.98 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.97 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.96 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.95 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.94 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.93 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.92 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.91 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.90 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.89 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.88 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.87 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.86 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.85 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.84 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.83 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.82 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.81 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.80 tracks/sml/exercises/binary/example.sml
trackler-2.2.1.79 tracks/sml/exercises/binary/example.sml