Skip to content

Commit

Permalink
Fixed codespaces for debugging and fixed day2p1
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdiel committed Dec 7, 2023
1 parent 0437d56 commit 1102fba
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [Choice] Ruby version: 2, 2.7, 2.6, 2.5
ARG VARIANT=2
ARG VARIANT=3.2
FROM mcr.microsoft.com/vscode/devcontainers/ruby:${VARIANT}

# [Option] Install Node.js
Expand Down
42 changes: 34 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"customizations": {
"vscode": {
"extensions": [
"Shopify.ruby-lsp"
]
}
"name": "Ruby",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update 'VARIANT' to pick a Ruby version: 2, 2.7, 2.6, 2.5
"VARIANT": "3.2",
// Options
"INSTALL_NODE": "true",
"NODE_VERSION": "lts/*"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"rebornix.Ruby"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "ruby --version",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/ruby:1": {}
}
}

}
6 changes: 2 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
"configurations": [

{
"type": "ruby-debug",
"type": "rdbg",
"request": "launch",
"name": "Active File",
"program": "${file}",
"programArgs": [],
"useBundler": false
"script": "${file}"
}
]
}
8 changes: 4 additions & 4 deletions 2023/day2/part1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ def grab_valid(grab)
if color[0].to_i > GREEN
return false
else
break
next
end
elsif color[1].upcase == "RED"
if color[0].to_i > RED
return false
else
break
next
end
elsif color[1].upcase == "BLUE"
if color[0].to_i > BLUE
return false
else
break
next
end
else
return false
Expand All @@ -50,7 +50,7 @@ def get_game_id(game_header)
end

id_sum = 0
File.open("test.txt","r") do |file|
File.open(File.join(File.dirname(__FILE__), "input.txt"), "r") do |file|
file.each_line do | line |
game = line.split(":")
game_id = get_game_id(game[0]).to_i
Expand Down
66 changes: 66 additions & 0 deletions 2023/day2/part2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Number of Cubes
RED = 12
GREEN = 13
BLUE = 14

def grab_valid(grab)
grab = grab.split(",")

grab.each do | colors |
color = colors.split(" ")
if color[1].upcase == "GREEN"
if color[0].to_i > GREEN
return false
else
next
end
elsif color[1].upcase == "RED"
if color[0].to_i > RED
return false
else
next
end
elsif color[1].upcase == "BLUE"
if color[0].to_i > BLUE
return false
else
next
end
else
return false
end
end
return true
end

def game_valid(game_data)
grabs = game_data.split(";")

grabs.each do | grab|
unless grab_valid(grab)
return false
end
end
return true
end

def get_game_id(game_header)
id = game_header.split(" ")
id = id[1]
end

id_sum = 0
File.open(File.join(File.dirname(__FILE__), "input.txt"), "r") do |file|
file.each_line do | line |
game = line.split(":")
game_id = get_game_id(game[0]).to_i
raw_game_data = game[1]

if game_valid(raw_game_data)
id_sum += game_id
end
end
end


puts id_sum

0 comments on commit 1102fba

Please sign in to comment.