day 8 complete

This commit is contained in:
Tanishq Dubey 2022-12-10 20:49:10 -05:00
parent 99db573cb2
commit bda214c07a
6 changed files with 296 additions and 0 deletions

86
day8/.gitignore vendored Normal file
View File

@ -0,0 +1,86 @@
node_modules/
.node_modules/
built/*
tests/cases/rwc/*
tests/cases/test262/*
tests/cases/perf/*
!tests/cases/webharness/compilerToString.js
test-args.txt
~*.docx
\#*\#
.\#*
tests/baselines/local/*
tests/baselines/local.old/*
tests/services/baselines/local/*
tests/baselines/prototyping/local/*
tests/baselines/rwc/*
tests/baselines/test262/*
tests/baselines/reference/projectOutput/*
tests/baselines/local/projectOutput/*
tests/baselines/reference/testresults.tap
tests/services/baselines/prototyping/local/*
tests/services/browser/typescriptServices.js
src/harness/*.js
src/compiler/diagnosticInformationMap.generated.ts
src/compiler/diagnosticMessages.generated.json
src/parser/diagnosticInformationMap.generated.ts
src/parser/diagnosticMessages.generated.json
rwc-report.html
*.swp
build.json
*.actual
tests/webTestServer.js
tests/webTestServer.js.map
tests/webhost/*.d.ts
tests/webhost/webtsc.js
tests/cases/**/*.js
!tests/cases/docker/*.js/
tests/cases/**/*.js.map
*.config
scripts/eslint/built/
scripts/debug.bat
scripts/run.bat
scripts/**/*.js
scripts/**/*.js.map
coverage/
internal/
**/.DS_Store
.settings
**/.vs
**/.vscode/*
!**/.vscode/tasks.json
!**/.vscode/settings.template.json
!**/.vscode/launch.template.json
!**/.vscode/extensions.json
!tests/cases/projects/projectOption/**/node_modules
!tests/cases/projects/NodeModulesSearch/**/*
!tests/baselines/reference/project/nodeModules*/**/*
.idea
yarn.lock
yarn-error.log
.parallelperf.*
tests/cases/user/*/package-lock.json
tests/cases/user/*/node_modules/
tests/cases/user/*/**/*.js
tests/cases/user/*/**/*.js.map
tests/cases/user/*/**/*.d.ts
!tests/cases/user/zone.js/
!tests/cases/user/bignumber.js/
!tests/cases/user/discord.js/
tests/baselines/reference/dt
.failed-tests
TEST-results.xml
package-lock.json
tests/cases/user/npm/npm
tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
tests/cases/user/create-react-app/create-react-app
tests/cases/user/fp-ts/fp-ts
tests/cases/user/webpack/webpack
tests/cases/user/puppeteer/puppeteer
tests/cases/user/axios-src/axios-src
tests/cases/user/prettier/prettier
.eslintcache

5
day8/inp Normal file
View File

@ -0,0 +1,5 @@
30373
25512
65332
33549
35390

99
day8/input 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

5
day8/package.json Normal file
View File

@ -0,0 +1,5 @@
{
"devDependencies": {
"@types/node": "^18.11.10"
}
}

94
day8/solution.ts Normal file
View File

@ -0,0 +1,94 @@
import { readFileSync } from 'fs';
import { join } from 'path';
const MINH = 0;
const MAXH = 9;
const getColumns = (arr, indices) => arr.map(row => indices.map(i => row[i])).reduce((accumulator, value) => accumulator.concat(value), []);
const fileString = readFileSync(join(__dirname, "input"), 'utf-8');
var rows = fileString.split("\n");
rows = rows.map(val => {
return val.trim();
});
rows = rows.filter(val => {
return val.length > 0;
});
const gridR = rows.map(val => {
return val.split("");
});
const grid = gridR.map(val => {
return val.map(vval => {
return +vval;
});
});
var visible = 0;
for (var i = 0; i < grid.length; i++) {
for (var j = 0; j < grid[i].length; j++) {
const tree = grid[i][j];
if (i - 1 < 0) { // Top of grid
visible += 1;
continue;
}
if (i + 1 >= grid.length) { // Bottom of grid
visible += 1;
continue;
}
if (j - 1 < 0) { // Left of grid
visible += 1;
continue;
}
if (j + 1 >= grid[i].length) { // Right of grid
visible += 1;
continue;
}
if (
(tree > Math.max(...grid[i].slice(0, j))) || // Check Left in row
(tree > Math.max(...grid[i].slice(j + 1))) || // Check Left in row
(tree > Math.max(...getColumns(grid, [j]).slice(0, i))) || // Check Left in row
(tree > Math.max(...getColumns(grid, [j]).slice(i + 1))) // Check Left in row
) {
visible += 1;
}
}
}
console.log(visible);
var maxScore = 0;
for (var i = 0; i < grid.length; i++) {
for (var j = 0; j < grid[i].length; j++) {
const tree = grid[i][j];
const left = grid[i].slice(0, j).reverse();
const right = grid[i].slice(j + 1);
const top = getColumns(grid, [j]).slice(0, i).reverse();
const bot = getColumns(grid, [j]).slice(i + 1);
const checks = [left, right, top, bot];
var scores = [];
for (const check of checks) {
var cscore = 0;
for (var k = 0; k < check.length; k++) {
cscore += 1;
if (tree <= check[k]) {
break;
}
}
scores.push(cscore);
}
const score = scores.reduce( (a,b) => a * b );
if (score > maxScore) {
maxScore = score;
}
}
}
console.log(maxScore);

7
day8/tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"compilerOptions": {
"types": [
"node"
]
}
}