0 people like it.

file1.fsx

построение дерева решений

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
open System
[   "Наличие бомбурий",         ["Да";      "Да";        "Нет";       "Да";    "Нет"]
    "Количество клептиконов",   ["1";       "1";         "0";         "3";     "5"]
    "Цвет велория",             ["Красный"; "Оранжевый"; "Оранжевый"; "—";     "Синий"]
    "Наличие пумпеля",          ["Нет";     "Да";        "Да";        "—";     "—"]
    "Величина пумпеля",         ["—";       "Большой";   "Маленький"; "—";     "—"]
    "Возможность крокотания",   ["Нет";     "Нет";       "—";         "Да";    "Нет"]
    "Возможность бульботания",  ["Нет";     "Да";        "—";         "Да";    "Нет"]
    "Наличие дуков и труков",   ["—";       "—";         "—";         "—";     "Да"]
    "Цвет лемпелей",            ["Жёлтый";  "Жёлтый";    "Жёлтый";    "Белый"; "Белый"]
    "Наличие пильских трапков", ["Да";      "Да";        "Да";        "Да";    "Да"]]
|> List.fold( fun bugs (question, xs) -> 
    if bugs |> List.filter Option.isSome |> List.length < 2 then bugs else
    let replies = 
        Set.ofList xs |> Set.fold( fun s x ->
        sprintf "%s%s\\"%s
    printfn "Введите \\"%s
    let answer = System.Console.ReadLine()
    if answer="-" then bugs else
        xs |> List.zip bugs |> List.map( function  
            | Some bug, v when v=answer || v="-" -> Some bug
            | _ -> None) ) ( [  "Аурата сетуньская"
                                "Десятилиньята лепая"
                                "Семипунктата Коха"
                                "Популий грыжомельский"
                                "Гортикола филоперьевая" ] |> List.map Some )
|> List.choose (fun x -> x) |> function
| [] -> printfn "ответ не найден"
| [x] -> printfn "Ответ - %s" x
| xs -> 
    printfn "Ответы:"
    xs |> List.iter (printfn "%s")
namespace System
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 bugs : obj option list
val question : string
val xs : string list
val filter : predicate:('T -> bool) -> list:'T list -> 'T list

Full name: Microsoft.FSharp.Collections.List.filter
module Option

from Microsoft.FSharp.Core
val isSome : option:'T option -> bool

Full name: Microsoft.FSharp.Core.Option.isSome
val length : list:'T list -> int

Full name: Microsoft.FSharp.Collections.List.length
val replies : (Set<'a> -> Set<string>) (requires comparison)
Multiple items
module Set

from Microsoft.FSharp.Collections

--------------------
type Set<'T (requires comparison)> =
  interface IComparable
  interface IEnumerable
  interface IEnumerable<'T>
  interface ICollection<'T>
  new : elements:seq<'T> -> Set<'T>
  member Add : value:'T -> Set<'T>
  member Contains : value:'T -> bool
  override Equals : obj -> bool
  member IsProperSubsetOf : otherSet:Set<'T> -> bool
  member IsProperSupersetOf : otherSet:Set<'T> -> bool
  ...

Full name: Microsoft.FSharp.Collections.Set<_>

--------------------
new : elements:seq<'T> -> Set<'T>
val ofList : elements:'T list -> Set<'T> (requires comparison)

Full name: Microsoft.FSharp.Collections.Set.ofList
val fold : folder:('State -> 'T -> 'State) -> state:'State -> set:Set<'T> -> 'State (requires comparison)

Full name: Microsoft.FSharp.Collections.Set.fold
val s : Set<string>
val x : 'a (requires comparison)
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
type Console =
  static member BackgroundColor : ConsoleColor with get, set
  static member Beep : unit -> unit + 1 overload
  static member BufferHeight : int with get, set
  static member BufferWidth : int with get, set
  static member CapsLock : bool
  static member Clear : unit -> unit
  static member CursorLeft : int with get, set
  static member CursorSize : int with get, set
  static member CursorTop : int with get, set
  static member CursorVisible : bool with get, set
  ...

Full name: System.Console
Console.ReadLine() : string
val zip : list1:'T1 list -> list2:'T2 list -> ('T1 * 'T2) list

Full name: Microsoft.FSharp.Collections.List.zip
val map : mapping:('T -> 'U) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val choose : chooser:('T -> 'U option) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.choose
val iter : action:('T -> unit) -> list:'T list -> unit

Full name: Microsoft.FSharp.Collections.List.iter
Raw view New version

More information

Link:http://fssnip.net/oF
Posted:2 years ago
Author:fpawel
Tags: script , tryfsharp