Created
April 17, 2013 11:39
-
-
Save zaneli/5403599 to your computer and use it in GitHub Desktop.
「再帰関数を Collections.Seq 系関数に書き換える」ブログ用
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
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 () |
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
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