4 people like it.

Write roman numerals

Just a pendant to Naveen's readromannumerals; takes an int and produces a roman numeral string

1: 
2: 
3: 
4: 
5: 
6: 
let writeroman n =
    let numerals = [(1000, "M"); (900, "CM"); (500, "D"); (400, "CD"); (100, "C");
                   (90, "XC"); (50, "L"); (40, "XL"); (10, "X"); (9, "IX");
                   (5, "V"); (4, "IV"); (1, "I")]
    let rec acc (v, r) (m, s) = if (v < m) then (v, r) else acc (v-m, r+s) (m, s)
    List.fold acc (n, "") numerals |> snd
val writeroman : n:int -> string

Full name: Script.writeroman
val n : int
val numerals : (int * string) list
val acc : (int * string -> int * string -> int * string)
val v : int
val r : string
val m : int
val s : string
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val fold : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State

Full name: Microsoft.FSharp.Collections.List.fold
val snd : tuple:('T1 * 'T2) -> 'T2

Full name: Microsoft.FSharp.Core.Operators.snd
Raw view New version

More information

Link:http://fssnip.net/8h
Posted:5 years ago
Author:Jonas Avelin
Tags: strings