Skip to content

Instantly share code, notes, and snippets.

@BrutalSimplicity
Created November 21, 2018 21:26
Show Gist options
  • Save BrutalSimplicity/5f47ed1a81b900287f1ef9c04e2df266 to your computer and use it in GitHub Desktop.
Save BrutalSimplicity/5f47ed1a81b900287f1ef9c04e2df266 to your computer and use it in GitHub Desktop.
One of our restaurant clients wants to know which pizza topping combinations are the most popular. Write a throw-away .NET console application that will download orders directly from http://files.olo.com/pizzas.json and output the top 20 most frequently ordered pizza topping combinations. List the toppings for each popular pizza topping combinat…
open FSharp.Data
type Pizza = JsonProvider<"pizzas.json">
type ToppingFrequencyPair = { Toppings: string[]; Frequency: int }
let getToppingFrequencyPair grouping =
{ Toppings = fst grouping; Frequency = snd grouping |> Array.length }
[<EntryPoint>]
let main argv =
let bestToppings =
Pizza.Load "http://files.olo.com/pizzas.json"
|> Array.groupBy (fun x -> x.Toppings |> Array.sort)
|> Array.map getToppingFrequencyPair
|> Array.sortByDescending (fun x -> x.Frequency)
|> Array.take 20
bestToppings |> Array.map (fun x -> printfn "%A" x) |> ignore
0 // return an integer exit code
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Data" Version="3.0.0" />
</ItemGroup>
</Project>
@BrutalSimplicity
Copy link
Author

{Toppings = [|"pepperoni"|];
 Frequency = 4616;}
{Toppings = [|"mozzarella cheese"|];
 Frequency = 1014;}
{Toppings = [|"four cheese"|];
 Frequency = 956;}
{Toppings = [|"bacon"|];
 Frequency = 732;}
{Toppings = [|"beef"|];
 Frequency = 623;}
{Toppings = [|"sausage"|];
 Frequency = 402;}
{Toppings = [|"italian sausage"|];
 Frequency = 361;}
{Toppings = [|"chicken"|];
 Frequency = 229;}
{Toppings = [|"four cheese"; "pepperoni"|];
 Frequency = 203;}
{Toppings = [|"ham"|];
 Frequency = 165;}
{Toppings = [|"mushrooms"|];
 Frequency = 159;}
{Toppings = [|"mozzarella cheese"; "pepperoni"|];
 Frequency = 155;}
{Toppings = [|"beef"; "pepperoni"|];
 Frequency = 122;}
{Toppings = [|"bacon"; "pepperoni"|];
 Frequency = 121;}
{Toppings = [|"black olives"|];
 Frequency = 117;}
{Toppings = [|"alredo sauce"|];
 Frequency = 101;}
{Toppings = [|"pepperoni"; "sausage"|];
 Frequency = 96;}
{Toppings = [|"cheddar cheese"|];
 Frequency = 95;}
{Toppings = [|"italian sausage"; "pepperoni"|];
 Frequency = 85;}
{Toppings = [|"pineapple"|];
 Frequency = 79;}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment