day 9 pt 1 done
This commit is contained in:
parent
bda214c07a
commit
dc2dd99c2a
86
day9/.gitignore
vendored
Normal file
86
day9/.gitignore
vendored
Normal 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
|
8
day9/input
Normal file
8
day9/input
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
R 5
|
||||||
|
U 8
|
||||||
|
L 8
|
||||||
|
D 3
|
||||||
|
R 17
|
||||||
|
D 10
|
||||||
|
L 25
|
||||||
|
U 20
|
5
day9/package.json
Normal file
5
day9/package.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^18.11.10"
|
||||||
|
}
|
||||||
|
}
|
81
day9/solution.ts
Normal file
81
day9/solution.ts
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
function distance(p1: number[], p2: number[]): number {
|
||||||
|
var x = p1[0] - p2[0];
|
||||||
|
var y = p1[1] - p2[1];
|
||||||
|
return Math.abs(x) + Math.abs(y)
|
||||||
|
}
|
||||||
|
|
||||||
|
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
||||||
|
|
||||||
|
const fileString = readFileSync(join(__dirname, "inp"), 'utf-8');
|
||||||
|
var commands = fileString.split("\n");
|
||||||
|
commands = commands.filter(val => {
|
||||||
|
return val.length > 0;
|
||||||
|
})
|
||||||
|
commands = commands.map(val => {
|
||||||
|
return val.trim();
|
||||||
|
})
|
||||||
|
const cmds = commands.map(val => {
|
||||||
|
return val.split(" ");
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(cmds);
|
||||||
|
|
||||||
|
var positions = {};
|
||||||
|
|
||||||
|
var pointlist = [];
|
||||||
|
const POINTS = 10;
|
||||||
|
for (var l = 0; l < POINTS; l++) {
|
||||||
|
pointlist.push([0, 0])
|
||||||
|
}
|
||||||
|
positions[pointlist[0].toString()] = 1;
|
||||||
|
|
||||||
|
for (const command of cmds) {
|
||||||
|
const direction = command[0];
|
||||||
|
const count = +command[1];
|
||||||
|
for (var j = 0; j < POINTS; j++){
|
||||||
|
for (var k = 0; k < count; k ++) {
|
||||||
|
if (j == 0) {
|
||||||
|
switch(direction) {
|
||||||
|
case 'U':
|
||||||
|
pointlist[j] = [pointlist[j][0], pointlist[j][1] + 1];
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
pointlist[j] = [pointlist[j][0], pointlist[j][1] - 1];
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
pointlist[j] = [pointlist[j][0] - 1, pointlist[j][1]];
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
pointlist[j] = [pointlist[j][0] + 1, pointlist[j][1]];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var currentPosition = pointlist[j];
|
||||||
|
var currentHeadPosition = pointlist[j - 1];
|
||||||
|
if (
|
||||||
|
(Math.abs(currentHeadPosition[0] - currentPosition[0]) > 1) ||
|
||||||
|
(Math.abs(currentHeadPosition[1] - currentPosition[1]) > 1)
|
||||||
|
) {
|
||||||
|
var xdiff = clamp(currentHeadPosition[0] - currentPosition[0], -1, 1);
|
||||||
|
var ydiff = clamp(currentHeadPosition[1] - currentPosition[1], -1, 1);
|
||||||
|
currentPosition = [currentPosition[0] + xdiff, currentPosition[1] + ydiff];
|
||||||
|
pointlist[j] = currentPosition;
|
||||||
|
|
||||||
|
if (j == 9) {
|
||||||
|
if(currentPosition.toString() in positions) {
|
||||||
|
positions[currentPosition.toString()] += 1;
|
||||||
|
} else {
|
||||||
|
positions[currentPosition.toString()] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(pointlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(Object.keys(positions).length);
|
7
day9/tsconfig.json
Normal file
7
day9/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": [
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user