Skip to content

Commit

Permalink
ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHi committed Dec 27, 2023
1 parent 176a5e4 commit d9951a6
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Ruby/2023/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules/
23 changes: 22 additions & 1 deletion Ruby/2023/.idea/2023.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Ruby/2023/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tabWidth: 2
semi: false
singleQuote: true
trailingComma: "none"

rubyArrayLiteral: true
rubyHashLabel: true
rubyModifier: true
rubySingleQuote: true
rubyToProc: false
40 changes: 30 additions & 10 deletions Ruby/2023/d2/day02.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Ruby/2023/gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'
gem 'rubocop', group: 'development', require: false
gem 'standard', group: 'development', require: false
gem 'syntax_tree'
59 changes: 59 additions & 0 deletions Ruby/2023/gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions Ruby/2023/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Ruby/2023/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"@prettier/plugin-ruby": "^4.0.4",
"prettier": "^3.1.1"
}
}
35 changes: 7 additions & 28 deletions Typescript/2023/src/days/day23/day23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,20 @@ export function SolvePartTwo(): number {
return path;
}

function dfs(start: string, end: string, g: Map<string, HikingNode>): number {
const visited: Set<string> = 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<string, HikingNode>, 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);

Expand Down Expand Up @@ -141,3 +118,5 @@ function mapSlopeToDelta(slope: string): Point {
throw new Error("Unknown slope");
}
}

function parseToGraph() {}

0 comments on commit d9951a6

Please sign in to comment.