Created
September 25, 2020 03:10
-
-
Save Jay-Madden/df48c452fed3f22ec297acf2bfddc386 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
namespace TestApp | |
{ | |
internal class Stuff | |
{ | |
public List<string> toppings { get; set; } | |
public uint GetUHash() | |
{ | |
uint hash = 0; | |
foreach (var i in toppings) | |
{ | |
unchecked | |
{ | |
hash += (uint)i.GetHashCode(); | |
} | |
} | |
return hash; | |
} | |
} | |
internal class Program | |
{ | |
private static async Task Main(string[] args) | |
{ | |
HttpContent json = (await new HttpClient().GetAsync("http://files.olo.com/pizzas.json")).Content; | |
var data = JsonConvert.DeserializeObject<List<Stuff>>(await json.ReadAsStringAsync()); | |
var result = data | |
.GroupBy(x => x.GetUHash()) | |
.OrderByDescending(x => x.Count()) | |
.Take(20) | |
.ToDictionary(x => x.ToList()[0], x => x.Count()); | |
var output = string.Join("\n", | |
result.Select((x, i) => | |
$"{string.Join(",", x.Key.toppings)}")); | |
var a = 9; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment