init and 2024 day 1
This commit is contained in:
commit
455ea925eb
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
56
Scenes/2024/01.gd
Normal file
56
Scenes/2024/01.gd
Normal file
|
@ -0,0 +1,56 @@
|
|||
extends Control
|
||||
|
||||
func _on_quit_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://Scenes/2024/2024.tscn")
|
||||
|
||||
@onready var input_edit: TextEdit = $Input
|
||||
@onready var error_label: Label = $Error
|
||||
@onready var part_1_out: Label = $Part1Out
|
||||
@onready var part_2_out: Label = $Part2Out
|
||||
|
||||
func _on_go_pressed() -> void:
|
||||
var input_text = input_edit.text
|
||||
part_1_out.text = part_1(input_text)
|
||||
part_2_out.text = part_2(input_text)
|
||||
|
||||
func set_error(msg: String) -> void:
|
||||
error_label.text = msg
|
||||
|
||||
func part_1(input_text: String) -> String:
|
||||
var lines = split_lines(input_text)
|
||||
if lines == []:
|
||||
return ""
|
||||
return str(get_diff(lines[0], lines[1]))
|
||||
|
||||
func split_lines(input: String) -> Array[Array]:
|
||||
var lines = input.split("\n")
|
||||
var left = [];
|
||||
var right = [];
|
||||
for line in lines:
|
||||
var parts = line.split(" ")
|
||||
if parts.size() != 2:
|
||||
set_error("invalid input!")
|
||||
return []
|
||||
left.append(parts[0] as int)
|
||||
right.append(parts[1] as int)
|
||||
return [left, right]
|
||||
|
||||
func get_diff(left: Array, right: Array) -> int:
|
||||
left.sort()
|
||||
right.sort()
|
||||
var diff = 0
|
||||
for i in range(left.size()):
|
||||
diff += abs(right[i] - left[i])
|
||||
return diff
|
||||
|
||||
func part_2(input_text: String) -> String:
|
||||
var lines = split_lines(input_text)
|
||||
if lines == []:
|
||||
return ""
|
||||
return str(get_similarity(lines[0], lines[1]))
|
||||
|
||||
func get_similarity(left: Array, right: Array) -> int:
|
||||
var similarity = 0
|
||||
for n in left:
|
||||
similarity += n * right.count(n)
|
||||
return similarity
|
85
Scenes/2024/01.tscn
Normal file
85
Scenes/2024/01.tscn
Normal file
|
@ -0,0 +1,85 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cqbt3uasjeh53"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/2024/01.gd" id="1_qvnl7"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_qvnl7")
|
||||
|
||||
[node name="Input" type="TextEdit" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 11.0
|
||||
offset_top = 95.0
|
||||
offset_right = 275.0
|
||||
offset_bottom = 253.0
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 16.0
|
||||
offset_top = 58.0
|
||||
offset_right = 108.0
|
||||
offset_bottom = 81.0
|
||||
text = "Enter input:"
|
||||
|
||||
[node name="Go" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 284.0
|
||||
offset_right = 60.0
|
||||
offset_bottom = 315.0
|
||||
text = "Go!"
|
||||
|
||||
[node name="Quit" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 28.0
|
||||
offset_top = 472.0
|
||||
offset_right = 70.0
|
||||
offset_bottom = 503.0
|
||||
text = "Quit
|
||||
"
|
||||
|
||||
[node name="Part1Out" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 93.0
|
||||
offset_top = 342.0
|
||||
offset_right = 212.0
|
||||
offset_bottom = 365.0
|
||||
text = "Results go here"
|
||||
|
||||
[node name="Error" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 380.0
|
||||
offset_top = 288.0
|
||||
offset_right = 420.0
|
||||
offset_bottom = 311.0
|
||||
text = "Errors go here"
|
||||
|
||||
[node name="Part1Label" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 28.0
|
||||
offset_top = 340.0
|
||||
offset_right = 68.0
|
||||
offset_bottom = 363.0
|
||||
text = "Part 1:"
|
||||
|
||||
[node name="Part2Out" type="Label" parent="."]
|
||||
offset_left = 91.0
|
||||
offset_top = 385.0
|
||||
offset_right = 210.0
|
||||
offset_bottom = 408.0
|
||||
text = "Results go here"
|
||||
|
||||
[node name="Part2Label" type="Label" parent="."]
|
||||
offset_left = 26.0
|
||||
offset_top = 383.0
|
||||
offset_right = 77.0
|
||||
offset_bottom = 406.0
|
||||
text = "Part 2:"
|
||||
|
||||
[connection signal="pressed" from="Go" to="." method="_on_go_pressed"]
|
||||
[connection signal="pressed" from="Quit" to="." method="_on_quit_pressed"]
|
4
Scenes/2024/2024.gd
Normal file
4
Scenes/2024/2024.gd
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends Control
|
||||
|
||||
func _on_01_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://Scenes/2024/01.tscn")
|
21
Scenes/2024/2024.tscn
Normal file
21
Scenes/2024/2024.tscn
Normal file
|
@ -0,0 +1,21 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://bw07oo5tgdkg5"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/2024/2024.gd" id="1_yeqs6"]
|
||||
|
||||
[node name="2024" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_yeqs6")
|
||||
|
||||
[node name="01" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 8.0
|
||||
offset_bottom = 8.0
|
||||
text = "01
|
||||
"
|
||||
|
||||
[connection signal="pressed" from="01" to="." method="_on_01_pressed"]
|
7
Scenes/ui.gd
Normal file
7
Scenes/ui.gd
Normal file
|
@ -0,0 +1,7 @@
|
|||
extends Control
|
||||
|
||||
func _on_exit_pressed() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
func _on_2024_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://Scenes/2024/2024.tscn")
|
34
Scenes/ui.tscn
Normal file
34
Scenes/ui.tscn
Normal file
|
@ -0,0 +1,34 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://bknnd7hecv0uc"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/ui.gd" id="1_gks0l"]
|
||||
|
||||
[node name="UI" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_gks0l")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 2.0
|
||||
offset_top = 2.0
|
||||
offset_right = 1150.0
|
||||
offset_bottom = 649.0
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="2024" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "2024
|
||||
"
|
||||
|
||||
[node name="Exit" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Exit"
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/2024" to="." method="_on_2024_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/Exit" to="." method="_on_exit_pressed"]
|
1
icon.svg
Normal file
1
icon.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
After Width: | Height: | Size: 994 B |
37
icon.svg.import
Normal file
37
icon.svg.import
Normal file
|
@ -0,0 +1,37 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://jv4filyjdvf3"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
16
project.godot
Normal file
16
project.godot
Normal file
|
@ -0,0 +1,16 @@
|
|||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Advent of Code"
|
||||
run/main_scene="res://Scenes/ui.tscn"
|
||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
Loading…
Reference in a new issue