Skip to content

Instantly share code, notes, and snippets.

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`` () =
// 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([|','|])
File.ReadAllText("n")
.Split(',')
.OrderBy(x=>x)
.Select((s, i) => s
.Replace("\"", string.Empty)
.ToCharArray()
.Sum(c => c - 64)*++i).Sum();
//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#:
//---------------------------------------------------------------
// 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:
//
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
@monkieboy
monkieboy / akkaTypes.cs
Created November 9, 2015 13:35
Akka F#
namespace AkkaTypesCS
{
public class GreetCs
{
public GreetCs(string who)
{
Who = who;
}
public string Who { get; set; }
@monkieboy
monkieboy / repeating.fsx
Last active November 11, 2015 19:23
repeating
#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 November 15, 2015 14:54
Unfold to generate a sequence of turtle commands
#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 November 17, 2015 14:07
Playing with ranges
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