2 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" s (if String.IsNullOrEmpty s then "" else ", ") x ) ""
    printfn "Введите %s. Варианты ответа: %s либо тире если Вы не знаете ответ" question replies
    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 id |> 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 : string 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 : string
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 : string
val x : string
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
Multiple items
type String =
  new : value:char -> string + 7 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 2 overloads
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  member GetHashCode : unit -> int
  ...

Full name: System.String

--------------------
String(value: nativeptr<char>) : unit
String(value: nativeptr<sbyte>) : unit
String(value: char []) : unit
String(c: char, count: int) : unit
String(value: nativeptr<char>, startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
String(value: char [], startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : unit
String.IsNullOrEmpty(value: string) : bool
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val answer : string
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>
val bug : string
val v : string
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 id : x:'T -> 'T

Full name: Microsoft.FSharp.Core.Operators.id
val iter : action:('T -> unit) -> list:'T list -> unit

Full name: Microsoft.FSharp.Collections.List.iter

More information

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