From d9951a6e2ebcb57ebde19bcf426714e55229cc74 Mon Sep 17 00:00:00 2001 From: TimHi Date: Wed, 27 Dec 2023 15:46:03 +0100 Subject: [PATCH] ruby --- Ruby/2023/.gitignore | 2 + Ruby/2023/.idea/2023.iml | 23 +++++++++- Ruby/2023/.prettierrc.yml | 10 +++++ Ruby/2023/d2/day02.rb | 40 ++++++++++++----- Ruby/2023/gemfile | 4 ++ Ruby/2023/gemfile.lock | 59 +++++++++++++++++++++++++ Ruby/2023/package-lock.json | 37 ++++++++++++++++ Ruby/2023/package.json | 6 +++ Typescript/2023/src/days/day23/day23.ts | 35 +++------------ 9 files changed, 177 insertions(+), 39 deletions(-) create mode 100644 Ruby/2023/.gitignore create mode 100644 Ruby/2023/.prettierrc.yml create mode 100644 Ruby/2023/gemfile create mode 100644 Ruby/2023/gemfile.lock create mode 100644 Ruby/2023/package-lock.json create mode 100644 Ruby/2023/package.json diff --git a/Ruby/2023/.gitignore b/Ruby/2023/.gitignore new file mode 100644 index 0000000..5b04c74 --- /dev/null +++ b/Ruby/2023/.gitignore @@ -0,0 +1,2 @@ +.idea +node_modules/ diff --git a/Ruby/2023/.idea/2023.iml b/Ruby/2023/.idea/2023.iml index 378c027..3c78f8d 100644 --- a/Ruby/2023/.idea/2023.iml +++ b/Ruby/2023/.idea/2023.iml @@ -9,7 +9,28 @@ - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Ruby/2023/.prettierrc.yml b/Ruby/2023/.prettierrc.yml new file mode 100644 index 0000000..fee30b2 --- /dev/null +++ b/Ruby/2023/.prettierrc.yml @@ -0,0 +1,10 @@ +tabWidth: 2 +semi: false +singleQuote: true +trailingComma: "none" + +rubyArrayLiteral: true +rubyHashLabel: true +rubyModifier: true +rubySingleQuote: true +rubyToProc: false \ No newline at end of file diff --git a/Ruby/2023/d2/day02.rb b/Ruby/2023/d2/day02.rb index 3173780..5a2c0af 100644 --- a/Ruby/2023/d2/day02.rb +++ b/Ruby/2023/d2/day02.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def get_colors_num(input, color) input.scan(/\b(\d+) #{color}\b/).flatten.map(&:to_i) end @@ -6,19 +8,37 @@ def get_game_id(input) input.scan(/\bGame (\d+)\b/).flatten.map(&:to_i) end -def is_valid(line) - line.split(";").map{ | split | get_colors_num(split, "red").sum <= 12 && get_colors_num(split, "green").sum <= 13 && get_colors_num(split, "blue").sum <= 14}.all? {|el| el === true} +def valid?(line) + line + .split(';') + .map do |split| + get_colors_num(split, 'red').sum <= 12 && + get_colors_num(split, 'green').sum <= 13 && + get_colors_num(split, 'blue').sum <= 14 + end + .all? { |el| el === true } end def solve - data = true ? DATA.readlines : File.open(File.join(File.dirname(__FILE__), 'full.txt') - ).readlines.map(&:chomp) - - puts data.select { |line| - is_valid(line) - }.map { |l| get_game_id(l) }.flatten.sum - - data.map { |line| } + data = + ( + if true + DATA.readlines + else + File + .open(File.join(File.dirname(__FILE__), 'full.txt')) + .readlines + .map(&:chomp) + end + ) + + puts data + .select { |line| valid?(line) } + .map { |l| get_game_id(l) } + .flatten + .sum + + data.map { |line| } end solve diff --git a/Ruby/2023/gemfile b/Ruby/2023/gemfile new file mode 100644 index 0000000..491bdf8 --- /dev/null +++ b/Ruby/2023/gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +gem 'rubocop', group: 'development', require: false +gem 'standard', group: 'development', require: false +gem 'syntax_tree' diff --git a/Ruby/2023/gemfile.lock b/Ruby/2023/gemfile.lock new file mode 100644 index 0000000..6869fdc --- /dev/null +++ b/Ruby/2023/gemfile.lock @@ -0,0 +1,59 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + parallel (1.24.0) + parser (3.2.2.4) + ast (~> 2.4.1) + racc + prettier_print (1.2.1) + racc (1.7.3) + rainbow (3.1.1) + regexp_parser (2.8.3) + rexml (3.2.6) + rubocop (1.59.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.4) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.1) + syntax_tree (6.2.0) + prettier_print (>= 1.2.0) + unicode-display_width (2.5.0) + +PLATFORMS + x64-mingw-ucrt + +DEPENDENCIES + rubocop + standard + syntax_tree + +BUNDLED WITH + 2.5.3 diff --git a/Ruby/2023/package-lock.json b/Ruby/2023/package-lock.json new file mode 100644 index 0000000..1fd3d89 --- /dev/null +++ b/Ruby/2023/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "2023", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "@prettier/plugin-ruby": "^4.0.4", + "prettier": "^3.1.1" + } + }, + "node_modules/@prettier/plugin-ruby": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@prettier/plugin-ruby/-/plugin-ruby-4.0.4.tgz", + "integrity": "sha512-lCpvfS/dQU5WrwN3AQ5vR8qrvj2h5gE41X08NNzAAXvHdM4zwwGRcP2sHSxfu6n6No+ljWCVx95NvJPFTTjCTg==", + "dev": true, + "peerDependencies": { + "prettier": "^3.0.0" + } + }, + "node_modules/prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/Ruby/2023/package.json b/Ruby/2023/package.json new file mode 100644 index 0000000..3e452e6 --- /dev/null +++ b/Ruby/2023/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "@prettier/plugin-ruby": "^4.0.4", + "prettier": "^3.1.1" + } +} diff --git a/Typescript/2023/src/days/day23/day23.ts b/Typescript/2023/src/days/day23/day23.ts index 3e4ceef..05cdf0c 100644 --- a/Typescript/2023/src/days/day23/day23.ts +++ b/Typescript/2023/src/days/day23/day23.ts @@ -49,43 +49,20 @@ export function SolvePartTwo(): number { return path; } -function dfs(start: string, end: string, g: Map): number { - const visited: Set = new Set(); - const stack: string[] = [start]; - - while (stack.length > 0) { - const curr = stack.pop()!; - - if (curr === end) { - console.log(visited.size - 1); - return visited.size - 1; - } - - visited.add(curr); - - const neighbors = getNeighbors(curr, g, false); - for (const next of neighbors) { - if (!visited.has(next)) { - stack.push(next); - visited.add(next); - } - } - } - - return 0; -} - function DFS_exhaustive(start: Point, end: Point, hikingMap: Map, isSlippery = true): number { const stack: Array<[string, string[]]> = [[GetPointKey(start), [GetPointKey(start)]]]; const foundPaths: number[] = []; - + let aal = 0; while (stack.length > 0) { const [currentVertex, path] = stack.pop() ?? []; if (currentVertex === GetPointKey(end)) { // 94 90, 86, 82, 82, 74 foundPaths.push(path!.length - 2); //-2 because start/end? - console.log(Math.max(...foundPaths)); + if (path!.length > aal) { + aal = path!.length; + console.log(path!.length); + } } const neighbors = getNeighbors(currentVertex!, hikingMap, isSlippery); @@ -141,3 +118,5 @@ function mapSlopeToDelta(slope: string): Point { throw new Error("Unknown slope"); } } + +function parseToGraph() {}