From 455ea925ebacddf27bff7c565f5447dcde15f283 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 4 Dec 2024 23:02:57 +0000 Subject: [PATCH] init and 2024 day 1 --- .gitattributes | 2 + .gitignore | 3 ++ Scenes/2024/01.gd | 56 ++++++++++++++++++++++++++++ Scenes/2024/01.tscn | 85 +++++++++++++++++++++++++++++++++++++++++++ Scenes/2024/2024.gd | 4 ++ Scenes/2024/2024.tscn | 21 +++++++++++ Scenes/ui.gd | 7 ++++ Scenes/ui.tscn | 34 +++++++++++++++++ icon.svg | 1 + icon.svg.import | 37 +++++++++++++++++++ project.godot | 16 ++++++++ 11 files changed, 266 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Scenes/2024/01.gd create mode 100644 Scenes/2024/01.tscn create mode 100644 Scenes/2024/2024.gd create mode 100644 Scenes/2024/2024.tscn create mode 100644 Scenes/ui.gd create mode 100644 Scenes/ui.tscn create mode 100644 icon.svg create mode 100644 icon.svg.import create mode 100644 project.godot diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/Scenes/2024/01.gd b/Scenes/2024/01.gd new file mode 100644 index 0000000..19b42c3 --- /dev/null +++ b/Scenes/2024/01.gd @@ -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 diff --git a/Scenes/2024/01.tscn b/Scenes/2024/01.tscn new file mode 100644 index 0000000..fa9ea0e --- /dev/null +++ b/Scenes/2024/01.tscn @@ -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"] diff --git a/Scenes/2024/2024.gd b/Scenes/2024/2024.gd new file mode 100644 index 0000000..b7ea389 --- /dev/null +++ b/Scenes/2024/2024.gd @@ -0,0 +1,4 @@ +extends Control + +func _on_01_pressed() -> void: + get_tree().change_scene_to_file("res://Scenes/2024/01.tscn") diff --git a/Scenes/2024/2024.tscn b/Scenes/2024/2024.tscn new file mode 100644 index 0000000..acbae91 --- /dev/null +++ b/Scenes/2024/2024.tscn @@ -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"] diff --git a/Scenes/ui.gd b/Scenes/ui.gd new file mode 100644 index 0000000..93a594a --- /dev/null +++ b/Scenes/ui.gd @@ -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") diff --git a/Scenes/ui.tscn b/Scenes/ui.tscn new file mode 100644 index 0000000..c36ba9f --- /dev/null +++ b/Scenes/ui.tscn @@ -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"] diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..e286df3 --- /dev/null +++ b/icon.svg.import @@ -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 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..f178aa4 --- /dev/null +++ b/project.godot @@ -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"