Skip to content

Instantly share code, notes, and snippets.

View FSharpAndNaturalSpec
namespace ``When running tests the NaturalSpec library``
open NUnit.Framework
open NaturalSpec
open System
module ``Executing these tests will output meaningful result information`` =
let root r = Math.Sqrt r
[<Scenario>]
let ``Maths is fun`` () =
View Euler42
// F# Solution (ugly):
let mapArray s =
([|1.0..500.0|]
|> Array.map(fun p -> p/2.0*(p+1.0)))
|> Array.filter (fun e->e=(s |> Array.sum))
|> Array.length
let problem42() =
let client = new System.Net.WebClient()
client.DownloadString("https://projecteuler.net/project/resources/p042_words.txt").ToUpper().Replace("\"", "").Split([|','|])
View Euler22
File.ReadAllText("n")
.Split(',')
.OrderBy(x=>x)
.Select((s, i) => s
.Replace("\"", string.Empty)
.ToCharArray()
.Sum(c => c - 64)*++i).Sum();
View Euler 29
//F#:
open System
let mutable result = [4.0]
let problem29 a =
for i in [2.0..a] do
for e in [2.0..a] do
result <- Math.Pow(i, e)::result
Seq.distinct result |> Seq.length;;
//C#:
View Koan15
//---------------------------------------------------------------
// Apply Your Knowledge!
//
// Below is a list containing comma separated data about
// Microsoft's stock prices during March of 2012. Without
// modifying the list, programatically find the day with the
// greatest variance between the opening and closing price.
//
// The following functions may be of use:
//
View LogReader
let logFiles = System.IO.Directory.GetFiles("C:\\temp\\logs")
// foreach logfile i want to scan each line and match and select lines containing '9'
let selected =
logFiles
|> Array.map System.IO.File.ReadAllLines
let collected =
selected
View akkaTypes.cs
namespace AkkaTypesCS
{
public class GreetCs
{
public GreetCs(string who)
{
Who = who;
}
public string Who { get; set; }
View repeating.fsx
#load "Spirograph.fs"
open System.Drawing
open FSharp.TV.Spirograph
//let printTurtle turtle =
// printfn "%A" turtle
// turtle
//let repeat (items:seq<'a>) =
// let generator state =
@monkieboy
monkieboy / Generating.fs
Created Nov 15, 2015
Unfold to generate a sequence of turtle commands
View Generating.fs
#load "Spirograph.fs"
open System.Drawing
open FSharp.TV.Spirograph
let cmdsStripe =
[
curve3rd 60.0 5
turn -170.0
move 80
curve3rd 60.0 -5 ]
@monkieboy
monkieboy / range.fsx
Created Nov 17, 2015
Playing with ranges
View range.fsx
let (..) (start:int) (limit:int) =
let sequence = [start..limit]
let decapitate h t =
if t = List.empty
then [ h ]
else t |> List.rev
let reversed =
match sequence with