Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created May 26, 2015 18:47
Show Gist options
  • Save jamessdixon/6f7abb2df6cfbef4a21d to your computer and use it in GitHub Desktop.
Save jamessdixon/6f7abb2df6cfbef4a21d to your computer and use it in GitHub Desktop.
Art Show Business Logic Challenge Using FSharp
type Painting = {id:int;name:string;tags:string}
type ArtShow = {id:int;name:string;expectedAttendance:int;paintings:Painting list}
let painting0 = {id=0;
name="Starry Night";
tags="Impressionism;Nature"}
let painting1 = {id=1;
name="Sunday Afternoon on the Island of La Grande Jatte";
tags="Impressionism;Nature;LeisureActivities"}
let painting2 = {id=2;
name="Dogs Playing Poker";
tags="Modernism;LeisureActivities"}
let paintings = [painting0;painting1;painting2]
let artShow = {id=0;
name="Art Extravaganza";
expectedAttendance=1000;
paintings=paintings}
let numberOfPaintings = artShow.paintings |> Seq.length
let baseVisitors = artShow.expectedAttendance/numberOfPaintings
let tagSet = artShow.paintings |> Seq.map(fun p -> p.tags)
|> Seq.collect(fun t -> t.Split(';'))
|> Seq.groupBy(fun t -> t)
|> Seq.map(fun (id,t) -> id, t |> Seq.length)
tagSet
let visitorsPerTag = artShow.expectedAttendance / (tagSet |> Seq.length)
let tagSet' = tagSet |> Seq.map(fun (id,c) -> id, visitorsPerTag/ c )
tagSet'
let tagModifier(painting: Painting) =
let tags = painting.tags.Split(';')
tags |> Seq.map(fun pt -> tagSet' |> Seq.find(fun(t,c) -> pt = t))
|> Seq.sumBy(fun(t,c) -> c )
tagModifier(painting0)
tagModifier(painting1)
tagModifier(painting2)
artShow.paintings |> Seq.map(fun p -> p, tagModifier(p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment