Skip to content

Instantly share code, notes, and snippets.

View melston's full-sized avatar

Mark Elston melston

  • Candler, NC
  • 13:52 (UTC -04:00)
View GitHub Profile
@melston
melston / gist:8dcfb2e26de693f5c1eaee42ca682e48
Last active November 15, 2017 19:25
Another alternative FizzBuzz in F#
let cycle x = Seq.initInfinite (fun _ -> x) |> Seq.concat
let zipWith f xs ys = Seq.zip xs ys |> Seq.map (fun (x,y) -> f x y)
let fizz = seq ["";"";"fizz"] |> cycle
let buzz = seq ["";"";"";"";"buzz"] |> cycle
let bang = seq ["";"";"";"";"";"";"bang"] |> cycle
let boom = seq ["";"";"";"";"";"";"";"";"";"";"boom"] |> cycle
let numbers = seq [1 .. 115] |> Seq.map string
let fizzBuzz3 = zipWith (+) bang boom
|> zipWith (+) buzz
let genFB (v: int, s: string) =
fun (n, os) ->
match n%v with
| 0 -> (n, os+s)
| _ -> (n, os)
let getStr (v: int, s: string) =
if (String.length s > 0) then s else sprintf "%i" v
let fizzbuzz max =
let fizzbuzz2 rules n =
rules
|> List.choose
(fun (k, s) ->
match n % k with
| 0 -> Some s
| _ -> None )
|> function
| [] -> sprintf "%d" n
| e -> List.reduce (+) e
@melston
melston / cs
Created July 13, 2020 17:15
Rx/CSharp Scan function example
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Text.RegularExpressions;
namespace SplitObservableTest
{
class Program
{
static void Main(string[] args)