Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.