-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSharpConsole.fs
More file actions
81 lines (59 loc) · 2 KB
/
FSharpConsole.fs
File metadata and controls
81 lines (59 loc) · 2 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module Bob
open System
open System.Runtime.InteropServices.ComTypes
let stringInput (input: string): string = Console.ReadLine()
type WhatISay = {
Question: string
Yelling: string
SilentAddress: string
EverythingElse: string
WhiteSpace: string
}
// type BobsResponse = {
// Whatever: string
// Fine: string
// Whoa: string
// Sure: string
// }
let BR = new BobsResponse
(
Fine = "Fine. Be that way!"
Whoa = "Whoa, chill out!"
Sure = "Sure."
)
let decideWhichResponse (WhatISay : string)
let responseCheck = Enum.GetValues(typeof<WhatISay>) |> Seq.cast<WhatISay>
for WhatISay in WhatISay do
match WhatISay with
| x when Seq.contains " ", " ", "", "\t\t\t\t\t\t\t\t\t\t" x -> bobsResponse.Whatever
| x when Seq.last.Equals("?") x -> bobsResponse.Sure
| x when Seq.last.Equals("!") x -> bobsResponse.Whoa
| x when Seq.contains whatISay.EverythingElse x -> bobsResponse.Whatever
| _ -> failwith failwith "*******<Teenagers>*******."
let response() = Console.WriteLine(decideWhichResponse)
// *******************************
module Leap
let leapYear (year: int) : bool =
match year with
| x when x % 4 <> 0 -> false
| x when x % 100 = 0 && x % 400 <> 0 -> false
| x when x % 4 = 0 && x % 100 <> 0 -> true
| x when x % 400 = 0 -> true
|_-> true
//************************************
let parseInt: char -> int = string >> int
let input = Seq.map parseInt "987654321"
let ifHeadIsLast s conc alt x =
match Seq.tryHead s, Seq.tryLast s with
| Some h, Some l -> if h = l then conc h x else alt x
| _ -> alt x
let pairwiseBy nextIdx values =
let arr = Array.ofSeq values
Array.mapi (fun i v -> v, arr.[nextIdx i]) arr
let len = Seq.length input
let answer =
input
|> pairwiseBy (fun i -> (i + len/2) % len)
|> Seq.sumBy (fun (a, b) -> if a = b then a else 0)
|> ifHeadIsLast input (fun h x -> h + x) (fun x -> x)
printfn "%A" answer