Add 2022/08/1

This commit is contained in:
kageru 2022-12-08 11:36:21 +01:00
parent 2d601b9bfb
commit 156512658f
3 changed files with 177 additions and 1 deletions

99
2022/inputs/day08 Normal file
View File

@ -0,0 +1,99 @@
422411333315050450444501456006152604434030162031174034546313212413064150120521030152355534203000121
301324204451515335252342253126503010214314026675523135330307170405066545120014006214521335013332134
410011302103513543254453460342420630261341511764171765703774273674310415535166643155002215230224343
103430412453541534313620414103230457371320115213510406561165762764547335046351220043205123531400041
431144033221543442550410360065613506340166441027415155772664554705330520251311025141223233351402243
213325510034542655030015455216430162202777001070241326522045362063054665216550230550303504355415521
031003015553250105046213533102217162325175605337032637035520465564170167670025216131512201354221154
030330000340601011142444407606503050007242464673750253830211547340373634150160430415326661303301345
113235411552011354533102340044621316346565585288537455721315631122136343660406713562561324015543445
421534130161456141524700000065614361134772508484820078328071864806605600741146570103520403345131004
431241004342502250214157404224401110285530841182417600676558252223422442223365151650333543165203252
452101220316500255542412735272327722260015722028635734835275716771361655446401456052405004343011243
510255424045455150311274151010862261804521785221564236521111375341822506140673475322206046102212233
250520346622520024422030262010116484388222015082111251607306033683521336835777306621444155166611242
433206064536135011234461674868743670524642527870325812423070432203771174543614556340531611610445224
104304050515243266345751017067540578262354859268542392474984317132267883577334573566666046443043404
120366016651172515376331617627075653459978432445841625981779145828376061131304637264456350043251114
245335211105601220505753552031605587244146668517552893732622278232503141724815237352500511536112534
503260136226330722271854285880226688399827276142943371411161827875170805326646134522345504215246054
434103313404230466231011205644364118651793541288242178723975136991327713565142203452660105341534666
265003443216157541264728634538467892327437689936965182594796577713795231766328573007210200224360245
013401313366563527475143586336181641242173553831166124462364333977722825747254704732661505446014514
264400525420160443306870177033344396594417316646926939377669646938458559703035212677520172110600241
004630122623524228000154527973258366988398838593697858788987515525679258590033574627002376260641356
615050624000232108162524551784918391547943589622457235227665558596142724177061417140002420755446226
232132277261663164874453478613224434392624523238848929879932567693369681122434202850441520043105130
106600246232518043804832541367163449466666777243694336727824433593713984577357407706446256672222242
216651306035603741820376317692246562923557968749548628946329882728321739597491054131510201323271340
256453574656662727688428449553769484663479668443552259939628676786573458655844467861272411137137001
525111477730681530651181964248627565399568482937993345844562732994586938452539541370054642201502146
625201525347502735649595171573335756623388874968974895469635738296582533333754884230352250000634121
353242650575747164146962171132883683286764988545995433449686677544695263235395576447462801654256543
310070674340222278423219475579342937579576666463739678353647639733577473976444418812427631672156356
065331511311700736484493626584438539836743843577399983895986454894252453455876697427118378115704064
366342527222306426476168325353725486948395534666887383954445698463536485756315269598423836835735170
405527420251714201479366889366685398468373864896735988793799654367288298948978414820338058117203005
061665105755712245171518865522286565963535963797666689384344637587726448772824838497658476715554554
263322504423128408124286677334968674987696356948458876787477573893592447348757546417678212053633504
012514277861726424756631776535326547379449767746986568845554936444589579955272551369383423682221227
352771363437852562254483955355279899747588948784997755867544448389854595976978866519907544427237324
422600752164868649628292844685267733788995978699996898798965664966973538729967431687206051003013312
154546254656081182312989543542385638755779776594559447448584898563398557696972197457457128240310565
500601113658843326553513723924744899657465646955784747997946478949776444972939248393436074123512232
235452162613381698198419542987546946658674976458999796554587855399695356746896855265556157235772535
666443516432258968314559277555393535799749579785559869974557456768773446599637392231195015286675357
560646660026804333113549593984873843468849949768876555656996979583958374454353779291258128023046237
530530375152278819342974958844687464665868888579959657966545645465595335533559872396861673433061451
115616051148768438276132332658368743957949577969768685877555854985437975777438776848568122532654532
112107255171134197454432259325399464855586566586877879987756675586849459977899993583522656434060153
437300074171728726623629837783445555646756497759857768957589565579457675746866311515127711801336146
427010366265286521292127599927874573944645867978587889978584688873894568394592975168655421882303066
711135225265514697559568555944366875786846987856897989796865694858887457823848766747732002210717770
542252516663131832681433736589538475694497987996595875599478754659995765459783771663847561232114010
230340208177328792549235253437546666595595978995555996899667457466596866425458772811326181702200116
272253537002546476819879698767959744778864486695797968896997686564843684256648359656578627613314622
032035377567104668716548545963339678455564646558587558766546574597756986386259258689475748308362227
423010731455185114359843667596454379577948687695985696959644966943745482822357537733597106181057404
621116676437302476442563593922358956657549647574699788489958549659757356397893982677915315742124640
354460540684745138189763234487858369565978479898866479778564785687384634628655249135395838206373763
472665706485721235298236392727967666593469684666448898476577667768536599563468413441463765252125545
400202770668748585723472583577456647539988599547479769546868944889599863962845468135164478163032272
452004753172577837829367353256949837587534685969458857464549593536456492658849888579441858023544267
307106335765173231917552537579728737647845666854874676947658788448375572755878282344847802815067767
263413150215476469482888275992779656753643847986745678699939485978467265252291315413664212526203360
442165010658623652564138593356488677439474649546495945893849463876793423896332291616280811734254136
243163267244734815979238272235266336343358699584764383764334555788587498544533996110126661277746506
456445206587151712744636539564345987853479474693774987657798876459758427794187491762847882751754515
035333260418848020092279916694879377835997734973388649555776677479522886284372218804361203442367301
402150177356205134769894175656866956543698378668365888475747465977248888764471111744655651717544356
322227633321833817473851247172293667659483698864374948487588893466347842732255393233057431233226652
220401747157676706006925878573877757652645753966765345568886778333756365629751324537365002624517423
656540752501165702738885714157463925335869549476334355966745862279547391777139653630260814457002525
160456117462163286230615654246747588466544295365576266322558234756563243941616283407720171553644356
025543134750640355668573191143246992939239773874989488889633959399832617222425627172210112046361432
023032002104706510283687857142569194687449899397269946782639254496554989353957504186850423000171606
552135233535715864671035592481178399825356644833529596263624746771246595159777114384422050506066104
604326307556552675658862139498712279284288674843723595288759969437368271924672604405211233552236632
466630103722066741367586708396513964124297394949355268764349529568152598482661861510265352710655366
425632154707051726502341134661919748136447776333497274223618594858144315316430705836503516230550201
432235603225433177631012637437916321653491758784152779972624444451648117446837184766066704536365110
541460013113674546210203782035617816692666689547565947794331166255665614154155856531106034740454310
550062365064176240658150551425321429643581692595534982348894946249725043175851364606262653042666033
324552402103237344211541478210503582935957227413435671879756259591605733820138573605644501560351101
033420532136721343204327650307884736586826275376892846129897116414757745320745250602706723165626331
213112346233516037452276606556815154086426533567662746775491781024667031868741773563623612151134220
040050334232133010736112340504617420744582864572276718923868000186150482840521722314206246011056240
311211546330604022404075645423046356874374712344518216782201525854717570648366531644625644526223554
512500221202230263764023410372308234576384103268046457074782442547774240200721713524231522254025424
003135563462204130753427546654647375830727262146328777453873815516821555134530116272000232165005102
034222520650060041405115642337577245014526275226176727605026853575348603071313502632544115252552001
434001410151104023367305301162455746126381624636332837244756548257666232310714704633343515001450504
500145305234025310110425552477312712570255016022350087642563505406037213447552470361344304541112525
011311542045202624341436677760452665060105354005528300464213350624322264777473513116064444441443041
123020050334444104436635210512431667424203407162118353422573656406433137113024104455516323422200105
304032110515430043562441664751116765706554132121573167535270035465171662347354021021312030154252342
432104214000502220335210425065146005665654103051026263133225256657056240121322550016364521150122103
332404122054310030151030160563463316530321605552450671743053414206243570221133250300024131523313231
110134030400213335406643022100613224612700424360067652140374413333643266103445350022401501023352131
231424301543353234613653325560166326262063626431047044000133041410622363320013444135310231215142114

68
2022/src/bin/day08.rs Normal file
View File

@ -0,0 +1,68 @@
#![feature(test)]
extern crate test;
use std::iter::repeat;
use aoc2022::{boilerplate, common::*};
const DAY: usize = 08;
type Parsed = Vec<Vec<u8>>;
fn parse_input(raw: &str) -> Parsed {
raw.lines().map(|l| l.as_bytes().to_vec()).collect()
}
fn is_visible_1d<'a>(iter: impl IntoIterator<Item = &'a u8>) -> Vec<bool> {
iter.into_iter()
.scan(0, |max, tree| {
let visible = tree > max;
*max = *tree.max(max);
Some(visible)
})
.collect()
}
fn part1(parsed: &Parsed) -> usize {
let a: Vec<_> = parsed.iter().map(is_visible_1d).collect();
let b: Vec<_> = parsed
.iter()
.map(|l| {
let mut v = is_visible_1d(l.iter().rev());
v.reverse();
v
})
.collect();
let c: Vec<_> = (0..parsed[0].len()).map(|i| is_visible_1d(parsed.iter().map(|row| &row[i]))).collect();
let d: Vec<_> = (0..parsed[0].len())
.map(|i| {
let mut v = is_visible_1d(parsed.iter().rev().map(|row| &row[i]));
v.reverse();
v
})
.collect();
(0..parsed.len()).flat_map(|i| repeat(i).zip(0..parsed[0].len())).filter(|&(i, j)| a[i][j] || b[i][j] || c[j][i] || d[j][i]).count()
}
fn part2(parsed: &Parsed) -> usize {
unimplemented!()
}
#[cfg(test)]
const TEST_OUTPUT: &[bool] = &[true, true, false, true, false];
boilerplate! {
TEST_INPUT == "30373
25512
65332
33549
35390",
tests: {
part1: { TEST_INPUT => 21 },
part2: { TEST_INPUT => 0 },
},
unittests: {
is_visible_1d: { [1, 3, 2, 4, 2] => TEST_OUTPUT, },
},
bench1 == 1543,
bench2 == 0,
bench_parse: Vec::len => 99,
}

View File

@ -3,8 +3,11 @@ macro_rules! boilerplate {
(
TEST_INPUT == $ti: literal,
tests: {
$($part: ident: { $($tpi: expr => $to: literal$(,)?)+ }$(,)?)*
$($part: ident: { $($tpi: expr => $to: expr),+$(,)? }),*$(,)?
},
$(unittests: {
$($unittest: ident: { $($utpi: expr => $uto: expr),+$(,)? }),*$(,)?
},)?
bench1 == $b1: literal,
bench2 == $b2: literal,
bench_parse: $input_fn: expr => $it: literal$(,)?
@ -23,6 +26,12 @@ macro_rules! boilerplate {
const TEST_INPUT: &str = $ti;
$($($(paste::paste! {
#[test]
fn [<$unittest _test_ $uto:lower>]() {
assert_eq!($unittest(&$utpi), $uto);
}
})+)*)?
$($(paste::paste! {
#[test]
fn [<$part _test_ $to:lower>]() {