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
public sealed class ProtobufNetBodyDeserializer : IBodyDeserializer | |
{ | |
public bool CanDeserialize(string contentType) | |
{ | |
return IsProtoBufType(contentType); | |
} | |
public object Deserialize(string contentType, Stream bodyStream, BindingContext context) | |
{ | |
// deserialize the body stream into the destination type |
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
public class MainModule : NancyModule | |
{ | |
public MainModule() | |
{ | |
Post["/bindProtobuf"] = | |
x => | |
{ | |
User data = this.Bind(); | |
return new Response |
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
public class ProtoBufResponse : Response | |
{ | |
public ProtoBufResponse(object body) | |
{ | |
ContentType = "application/x-protobuf"; | |
Contents = stream => ProtoBuf.Serializer.Serialize(stream, body); | |
} | |
public ProtoBufResponse WithStatusCode(HttpStatusCode httpStatusCode) | |
{ |
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
// a simple module to be hosted in the console app | |
public class MainModule : NancyModule | |
{ | |
public MainModule() | |
{ | |
Get["/"] = x => { return "Hello World"; }; | |
} | |
} | |
static void Main(string[] args) |
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
public class MainModule : NancyModule | |
{ | |
public MainModule() | |
{ | |
Get["/"] = x => | |
{ | |
return "This is the root."; | |
}; | |
} | |
} |
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.IO | |
let (answer, _) = | |
File.ReadAllLines(@"c:\temp\base_exp.txt") | |
|> Array.mapi (fun i l -> (i + 1, l.Split(',') |> Array.map float)) | |
|> Array.map (fun t -> match t with | (i, arr) -> (i, arr.[1] * (log arr.[0]))) | |
|> Array.maxBy (fun t -> match t with | (i, l) -> l) |
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.IO | |
let dimension = 80 | |
// load the original matrix | |
let matrix = array2D (File.ReadAllLines(@"c:\temp\matrix.txt") | |
|> Array.map (fun l -> l.Split(',') |> Array.map int32)) | |
// init the shortes sum matrix |
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 | |
let target = 2000000 | |
// function to work out the number of rects in a grid of x by y | |
let getRectCount x y = (x * x + x) * (y * y + y) / 4 | |
// try x and y dimensions up to 100 | |
let answer = | |
seq { |
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
// recursive function that'll return all the possible scores | |
let rec getScores numbers acc iter max = | |
if iter < max | |
then numbers |> List.collect (fun n -> getScores numbers (acc + n) (iter + 1) max) | |
else numbers |> List.map (fun n -> n + acc) | |
// gets the possible scores and the associated probability of achieving that score | |
let getScoreProbs numbers count = | |
// given the set of possible numbers on each dice and the number of dice | |
// what's the prob of getting each permutation (1, 1, 2, 3) |
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 predicate n = | |
let nStr = n.ToString() | |
// make sure n is a 19 digit number | |
if nStr.Length <> 19 then false | |
// check the number matches the pattern 1_2_3_4_5_6_7_8_9_0 | |
else [1..10] |> List.forall (fun i -> int(nStr.[2*(i-1)].ToString()) = i % 10) | |
// wonderful bit of brute force CPU.. | |
let answer = | |
let mutable n = 1000000000L |
OlderNewer