Skip to content

Instantly share code, notes, and snippets.

@zaneli
Created April 17, 2013 11:39
Show Gist options
  • Save zaneli/5403599 to your computer and use it in GitHub Desktop.
Save zaneli/5403599 to your computer and use it in GitHub Desktop.
「再帰関数を Collections.Seq 系関数に書き換える」ブログ用
open System
let rec loop () =
let line = Console.ReadLine()
if line <> null then
let numericStr =
line
|> Seq.takeWhile(fun s -> Char.IsNumber(s))
|> Seq.toArray
Console.WriteLine(numericStr)
loop ()
loop ()
open System
let rec loop () =
let line = Console.ReadLine()
if line <> null then
let notNumIndex = line |> Seq.tryFindIndex(fun s -> not(Char.IsNumber(s)))
match notNumIndex with
| Some (n) -> Console.WriteLine(line.[0 .. n - 1])
| None -> Console.WriteLine(line)
loop ()
loop ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment