3 people like it.

Project Euler Problem 19

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
open System

Seq.unfold (fun x ->
                if x > DateTime (2000,12,31) then
                    None
                else
                    Some (x, x.AddMonths(1)))(DateTime(1901,1,1))
|> Seq.filter (fun x -> x.DayOfWeek = DayOfWeek.Sunday)
|> Seq.length |> printfn "Problem 19 answer: %d"
namespace System
module Seq

from Microsoft.FSharp.Collections
val unfold : generator:('State -> ('T * 'State) option) -> state:'State -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.unfold
val x : DateTime
Multiple items
type DateTime =
  struct
    new : ticks:int64 -> DateTime + 10 overloads
    member Add : value:TimeSpan -> DateTime
    member AddDays : value:float -> DateTime
    member AddHours : value:float -> DateTime
    member AddMilliseconds : value:float -> DateTime
    member AddMinutes : value:float -> DateTime
    member AddMonths : months:int -> DateTime
    member AddSeconds : value:float -> DateTime
    member AddTicks : value:int64 -> DateTime
    member AddYears : value:int -> DateTime
    ...
  end

Full name: System.DateTime

--------------------
DateTime()
   (+0 other overloads)
DateTime(ticks: int64) : unit
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : unit
   (+0 other overloads)
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
DateTime.AddMonths(months: int) : DateTime
val filter : predicate:('T -> bool) -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.filter
property DateTime.DayOfWeek: DayOfWeek
type DayOfWeek =
  | Sunday = 0
  | Monday = 1
  | Tuesday = 2
  | Wednesday = 3
  | Thursday = 4
  | Friday = 5
  | Saturday = 6

Full name: System.DayOfWeek
field DayOfWeek.Sunday = 0
val length : source:seq<'T> -> int

Full name: Microsoft.FSharp.Collections.Seq.length
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view Test code New version

More information

Link:http://fssnip.net/88
Posted:10 years ago
Author:Gene Belitski
Tags: project euler , puzzles