-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
105 lines (79 loc) · 2.58 KB
/
Copy pathProgram.fs
File metadata and controls
105 lines (79 loc) · 2.58 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
//goal: every odd digit of a sin
let sin = "123 456 789"
let c = sin.[0]
let a = sin.ToCharArray()
let b = Seq.toList a
let d = Seq.toList sin
let c1:char = 'a'
let c2:char = 'b'
let nospace =
//List.filter (fun c -> c != ' ')
//List.filter (fun c -> not (c = ' ')) //huh.. char doesn't support !=
List.filter (fun c -> c = ' ' |> not) //lol
//let include c = function
// | [x] -> true
// | x:remainder -> x
let rec oddeven = function
| [] -> []
| [x] -> [x]
| x1::x2::xs ->
let nexty = oddeven xs
x1::nexty
//open System; let x = "abcdef01234567" |> Seq.take 5 |> String.Concat;;
let daStuff r:string = /// <-- methinks I meant to say (r:string) at the time...
let o =
r |>
Seq.toList |>
nospace |>
oddeven |>
List.toArray |>
(fun charArray -> new System.String(charArray))
o
//took a long break
let makeString (a: char list) =
List.fold (fun stringResultState char -> stringResultState + (string char) ) "" a
let makeString2 (a: char list) =
let seperator = ""
a |> List.map string |> String.concat seperator
let cheat (a: char list) =
let sb = new System.Text.StringBuilder()
a |> List.iter (fun c -> sb.Append(c) |> ignore)
sb.ToString()
let daNewStuff s =
s
|> Seq.toList
|> nospace
|> oddeven
|> makeString
let asIsInOne s =
s
|> Seq.toList
|> List.filter (fun ch -> not(ch = ' '))
|> oddeven
|> (fun f -> f)
|> List.map string
|> String.concat ""
let inOne s = //you can do it all without a list
s
|> Seq.filter (fun char -> not (char = ' '))
|> Seq.mapi (fun index element -> (element, index)) //tuple!
|> Seq.filter (fun (element, index) -> index % 2 = 0)
//|> Seq.map fst
//|> Seq.map string
|> Seq.map (fst >> string)
|> String.concat ""
//or
//|> Seq.fold (fun stringResultState char -> stringResultState + (string (fst char))) ""
//|> Seq.fold (fun stringResultState tuple -> tuple |> fst |> string |> (+) stringResultState ) ""
[<EntryPoint>]
let main argv =
printfn "args %A" argv
printfn "sin %A" sin
printfn "everyodd1 %A" (daNewStuff sin)
printfn "everyodd2 %A" (asIsInOne sin)
printfn "everyodd3 %A" (inOne sin)
if (System.Diagnostics.Debugger.IsAttached) then
System.Console.ReadKey() |> ignore
0 // return an integer exit code