This file contains 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
var str = "The quick brown fox jumped over the lazy dog. Hello-world! wOrLd WorLd. The new order!"; | |
var words = | |
new Regex(@"\b([A-Z-]+)\b", RegexOptions.IgnoreCase) | |
.Matches(str) | |
.Select(m => m.Groups[0].Value.ToLower()) | |
.GroupBy(g => g) | |
.Select(g => KeyValuePair.Create(g.Key, g.Count())) | |
.OrderByDescending(kv => kv.Value) | |
.ToDictionary(kv => kv.Key, kv => kv.Value); |
This file contains 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
var arr = new [] { 0, 2, 4, 6, 8, 10 }; | |
Func<int[], bool, Func<int, Tuple<bool, int>, bool>, bool> aggregate = | |
(a, b, fn) => a.Skip(2).Aggregate(Tuple.Create(b, a[1]), (res, i) => Tuple.Create(res.Item1 && fn(i, res), i)).Item1; | |
var diff = arr[1] - arr[0]; | |
var isA = aggregate(arr, true, (i, r) => i - r.Item2 == diff); | |
arr = new [] { 1, 2, 4, 8, 16, 32 }; | |
diff = arr[1] / arr[0]; |
This file contains 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
private static readonly Regex rx = new Regex(@"(\d)(\D+)?"); | |
public static string QuestionsMarks(string str) { | |
var input = rx.Matches(str).Select(m => Tuple.Create(Int32.Parse(m.Groups[1].Value), m.Groups[2].Value)).ToList(); | |
return input | |
.Zip(input.Skip(1), Tuple.Create) | |
.Where(t => t.Item1.Item1 + t.Item2.Item1 == 10) | |
.DefaultIfEmpty(Tuple.Create(Tuple.Create(0, ""), Tuple.Create(0, ""))) | |
.All(t => t.Item1.Item2.Count(c => c == '?') == 3) | |
.ToString() |
This file contains 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
private static readonly Regex rx = new Regex(@"\b(\w+)\b"); | |
public static string LongestWord(string sen) { | |
return rx.Matches(sen) | |
.Select(m => m.Groups[0].Value) | |
.Select(w => Tuple.Create(w, w.Length)) | |
.OrderByDescending(t => t.Item2) | |
.Select(t => t.Item1) | |
.FirstOrDefault(); | |
} |
This file contains 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 | |
open FSharp.Control | |
[<EntryPoint>] | |
let main _ = | |
let rec receiver () = | |
asyncSeq { | |
yield async.Return "." | |
yield! receiver () |
This file contains 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 | |
open System.Runtime.InteropServices | |
type X() = | |
static member Outist(x: string, y: int, [<Out>] z: string byref) = | |
z <- "tuO" | |
(y, x) | |
[<EntryPoint>] | |
let main argv = |
This file contains 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 | |
open FSharp.Control | |
[<EntryPoint>] | |
let main _ = | |
let rnd = Random() | |
let workflows = | |
[| | |
for x in 1 .. 100 -> | |
async { |
This file contains 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 | |
open BenchmarkDotNet.Attributes | |
open BenchmarkDotNet.Running | |
open BenchmarkDotNet.Jobs | |
open FSharp.Control.Tasks.V2 | |
[<SimpleJob(RuntimeMoniker.NetCoreApp31); MemoryDiagnoser>] | |
type Test() = | |
[<Params(100, 1000, 10000)>] |
This file contains 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 | |
open System.Threading | |
open System.Threading.Channels | |
open FSharp.Control | |
let channel = | |
Channel.CreateUnbounded<int>(UnboundedChannelOptions(SingleWriter=true, SingleReader=true)) | |
let mutable cnt = 0 | |
let timerEvent _ = |
This file contains 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
let reqs = [| 0 .. 6 |] | |
let chunks = [| 4; 1; 2 |] | |
let splitter rq ch = | |
let rec splitter' r (c:seq<int>) = seq { | |
if not(Seq.isEmpty c) then | |
let cx = c |> Seq.take 1 |> Seq.exactlyOne | |
yield r |> Seq.take cx | |
yield! splitter' (Seq.skip cx r) (Seq.skip 1 c) | |
} |
NewerOlder