Last active
December 1, 2022 11:27
-
-
Save aloisdg/782f2cf1ba9dedafc5aa0be2ff7270d8 to your computer and use it in GitHub Desktop.
Advent_2022_1
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; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var s = @"1000 | |
2000 | |
3000 | |
4000 | |
5000 | |
6000 | |
7000 | |
8000 | |
9000 | |
10000"; | |
var maxCalories = s | |
.Split("\n\n") | |
.Max(x => x.Split('\n').Sum(int.Parse)); | |
Console.WriteLine(maxCalories); | |
} | |
} |
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
// https://tio.run/##LYzLDsIgEEX3fMWkm0LUCb41Td278A@6KLZEayoQQNO/R6bxLk7uIzMv9VWh84OLK2N7nVJnTYgQoIZ2LaVkG8KWwHYz98TDbI/EE@E8ZzqQbcUYPbGjxtE@@E3FJ77VxBExYHDjEHnRmMYUIteOT1BfYPoPZWNKgV73n05zrpZwFzQ75YO@mshzXECupciqUvoB | |
const s = `1000 | |
2000 | |
3000 | |
4000 | |
5000 | |
6000 | |
7000 | |
8000 | |
9000 | |
10000`; | |
console.log(Math.max(...s.split("\n\n").map(x => x.split('\n').reduce((a, b) => parseInt(b) + a, 0)))); |
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; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var s = @"1000 | |
2000 | |
3000 | |
4000 | |
5000 | |
6000 | |
7000 | |
8000 | |
9000 | |
10000"; | |
var maxCalories = s | |
.Split("\n\n") | |
.Select(x => x.Split('\n').Sum(int.Parse)) | |
.OrderDescending() | |
.Take(3) | |
.Sum(); | |
Console.WriteLine(maxCalories); | |
} | |
} |
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
// https://tio.run/##bY3PDsIgDIfvPEXjZRA3gs6/Webdd9hhbCNmBoEAmr39pNODBy9f2v7ar3f5kqH3o4uFsYOa596aECFADe1GCEG2iBJBdgv3yMNSHpEnxHnp8UC0FSEfiU@SwIPTY6SrxjRmxfhDOjpBfYHpG2SNyRj3anj2ilKZQ8cwdtIHdTWRpnYNaSwYq4jnwfr4s9ZBATIF@NBqxbW90bSkxyQTOZR/zDL5uiSb5zc | |
const s = `1000 | |
2000 | |
3000 | |
4000 | |
5000 | |
6000 | |
7000 | |
8000 | |
9000 | |
10000`; | |
const r = s.split("\n\n").map(x => x.split('\n').reduce((a, b) => parseInt(b) + a, 0)); | |
r.sort((a, b) => b - a); | |
console.log(r.slice(0, 3).reduce((a, b) => a + b)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment