diff --git a/Euler.gd b/Euler.gd new file mode 100644 index 0000000..7e8192b --- /dev/null +++ b/Euler.gd @@ -0,0 +1,36 @@ +class_name EulerCalculator extends Control + + + +func _on_test_button_down() -> void: + var answer:int = calc_biggest_palindromic_number(2) + show_result(answer) + +func _on_calculate_button_down() -> void: + var answer:int = calc_biggest_palindromic_number(3) + show_result(answer) + +func show_result(answer:int) -> void: + $VBoxContainer/Label.text = str(answer) + +func calc_biggest_palindromic_number(digits:int) -> int: + var highest_palindrome:int = -1 + var min:int=pow(10,digits-1) + var max:int=pow(10,digits) + for a in range(min, max): + for b in range(min, max): + var p:int = a*b + var arr:Array = [0] + for k in range(1, digits*2+1): + var unit:int = p % (pow(10,k) as int) + unit /= (pow(10,k-1) as int) + arr.append(unit) + arr.remove_at(0) + if arr.size() != digits*2: + continue + var is_palindrome:bool = true + for k in range(0,digits): + is_palindrome = is_palindrome and arr[k] == arr[digits*2-k-1] + if is_palindrome and highest_palindrome - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {e5f5f7cd-3dcd-451d-851d-1a5547569bd9} - EulersProject - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/EulersProject.vcxproj.filters b/EulersProject.vcxproj.filters deleted file mode 100644 index 340b9d1..0000000 --- a/EulersProject.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Header Files - - - - - Header Files - - - \ No newline at end of file diff --git a/EulersProject.vcxproj.user b/EulersProject.vcxproj.user deleted file mode 100644 index 88a5509..0000000 --- a/EulersProject.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Exercises.cpp b/Exercises.cpp deleted file mode 100644 index f54e664..0000000 --- a/Exercises.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include "Exercises.h" - -// Gives multiple of all multiples of 3 or 5 under given number. -int Ex1(int in) { - int out = 0; - - for (int i = 3; i < in; i += 3) out += i; - for (int i = 5, t = 1; i < in; i += 5, t++) { - if (t == 3) t = 0; - else out += i; - } - return out; -} - -// Gives multiple of all even fibonacci sequence values under given number -int Ex2(int in) { - int v1 = 0, v2 = 1, f = 0, out = 0; - while (true) { - // calc fibonacci value - f = v1 + v2; - v1 = v2; - v2 = f; - - // stop if fibonacci value over max - if (in < f) break; - // skip if uneven - if ((f & 0b1) == 1) continue; - - // sum - out += f; - } - return out; -} - -/* -Works but needs to be optimised for large number: 600851475143 -*/ -// Gives biggest prime factor of given number -unsigned long long Ex3(unsigned long long in) { - vector primes = { 2 }; - unsigned long long biggest_prime = -1; - - for (unsigned long long num = 2; num <= in; num++) - { - // Find prime - bool isPrime = true; - for (auto prime : primes) - { - isPrime = num % prime != 0; - if (!isPrime) break; - } - if (!isPrime) continue; - primes.push_back(num); - - // Is number factor of input, if not go to next number. - if (in % num != 0) continue; - - // Save current prime as biggest prime and promote other factor as new max. - biggest_prime = num; - in = in / num; - } - return biggest_prime; -} \ No newline at end of file diff --git a/Exercises.h b/Exercises.h deleted file mode 100644 index 3c99c1e..0000000 --- a/Exercises.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -using namespace std; - -int Ex1(int x); -int Ex2(int x); -unsigned long long Ex3(unsigned long long in); diff --git a/Main.h b/Main.h deleted file mode 100644 index d1ee33e..0000000 --- a/Main.h +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include "Exercises.h" - -int main() -{ - while (true) { - // Input - char input; - cout << "Check(c), test(t) or quit(q) -> "; - cin >> input; - cout << endl; - - // action - auto t1 = std::chrono::high_resolution_clock::now(); - if (input == 'c') cout << "check result: " << Ex3(13195) << endl; - else if (input == 't') cout << "test result: " << Ex3(600851475143) << endl; - else if (input == 'q') break; - auto t2 = std::chrono::high_resolution_clock::now(); - auto duration_ns = std::chrono::duration_cast(t2 - t1).count(); - cout << "Duration = " << duration_ns << " microseconds" << endl; - } -} \ No newline at end of file diff --git a/README.md b/README.md index 5952aee..c254095 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # ProjectEuler -My source code for project Euler solutions +My source code for project Euler solutions. + + + +Implemented in gdscript. diff --git a/Timer.h b/Timer.h deleted file mode 100644 index 9349d65..0000000 --- a/Timer.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include -#include - -namespace tools -{ - template - class stopwatch - { - const typename Clock::time_point start_point; - public: - stopwatch() : - start_point(Clock::now()) - {} - - template - Rep elapsed_time() const - { - std::atomic_thread_fence(std::memory_order_relaxed); - auto counted_time = std::chrono::duration_cast(Clock::now() - start_point).count(); - std::atomic_thread_fence(std::memory_order_relaxed); - return static_cast(counted_time); - } - }; - - using precise_stopwatch = stopwatch<>; - using system_stopwatch = stopwatch; - using monotonic_stopwatch = stopwatch; -} \ No newline at end of file diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..adc26df --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..ac699a8 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c4suj7a7mivr7" +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..cedfb0e --- /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="GD-Euler" +run/main_scene="res://Euler.tscn" +config/features=PackedStringArray("4.0", "Forward Plus") +config/icon="res://icon.svg" diff --git a/x64/Debug/EulersProject.Build.CppClean.log b/x64/Debug/EulersProject.Build.CppClean.log deleted file mode 100644 index c48c6a3..0000000 --- a/x64/Debug/EulersProject.Build.CppClean.log +++ /dev/null @@ -1,13 +0,0 @@ -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\vc143.pdb -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\vc143.idb -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\main.obj -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\exercises.obj -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\eulersproject.ilk -c:\users\douwe\projects\eulersproject\x64\debug\eulersproject.pdb -c:\users\douwe\projects\eulersproject\x64\debug\eulersproject.exe -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\eulersproject.tlog\cl.command.1.tlog -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\eulersproject.tlog\cl.read.1.tlog -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\eulersproject.tlog\cl.write.1.tlog -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\eulersproject.tlog\link.command.1.tlog -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\eulersproject.tlog\link.read.1.tlog -c:\users\douwe\projects\eulersproject\eulersproject\x64\debug\eulersproject.tlog\link.write.1.tlog diff --git a/x64/Debug/EulersProject.exe.recipe b/x64/Debug/EulersProject.exe.recipe deleted file mode 100644 index ef6562f..0000000 --- a/x64/Debug/EulersProject.exe.recipe +++ /dev/null @@ -1,11 +0,0 @@ - - - - - C:\Users\douwe\Projects\EulersProject\x64\Debug\EulersProject.exe - - - - - - \ No newline at end of file diff --git a/x64/Debug/EulersProject.ilk b/x64/Debug/EulersProject.ilk deleted file mode 100644 index cc329fa..0000000 Binary files a/x64/Debug/EulersProject.ilk and /dev/null differ diff --git a/x64/Debug/EulersProject.log b/x64/Debug/EulersProject.log deleted file mode 100644 index fce1a1c..0000000 --- a/x64/Debug/EulersProject.log +++ /dev/null @@ -1 +0,0 @@ - EulersProject.vcxproj -> C:\Users\douwe\Projects\EulersProject\x64\Debug\EulersProject.exe diff --git a/x64/Debug/EulersProject.tlog/CL.command.1.tlog b/x64/Debug/EulersProject.tlog/CL.command.1.tlog deleted file mode 100644 index b757a14..0000000 Binary files a/x64/Debug/EulersProject.tlog/CL.command.1.tlog and /dev/null differ diff --git a/x64/Debug/EulersProject.tlog/CL.read.1.tlog b/x64/Debug/EulersProject.tlog/CL.read.1.tlog deleted file mode 100644 index 7d892a6..0000000 Binary files a/x64/Debug/EulersProject.tlog/CL.read.1.tlog and /dev/null differ diff --git a/x64/Debug/EulersProject.tlog/CL.write.1.tlog b/x64/Debug/EulersProject.tlog/CL.write.1.tlog deleted file mode 100644 index 1fddaa1..0000000 Binary files a/x64/Debug/EulersProject.tlog/CL.write.1.tlog and /dev/null differ diff --git a/x64/Debug/EulersProject.tlog/EulersProject.lastbuildstate b/x64/Debug/EulersProject.tlog/EulersProject.lastbuildstate deleted file mode 100644 index 1ae5b14..0000000 --- a/x64/Debug/EulersProject.tlog/EulersProject.lastbuildstate +++ /dev/null @@ -1,2 +0,0 @@ -PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.35.32215:TargetPlatformVersion=10.0.22000.0: -Debug|x64|C:\Users\douwe\Projects\EulersProject\| diff --git a/x64/Debug/EulersProject.tlog/link.command.1.tlog b/x64/Debug/EulersProject.tlog/link.command.1.tlog deleted file mode 100644 index 651a9d8..0000000 Binary files a/x64/Debug/EulersProject.tlog/link.command.1.tlog and /dev/null differ diff --git a/x64/Debug/EulersProject.tlog/link.read.1.tlog b/x64/Debug/EulersProject.tlog/link.read.1.tlog deleted file mode 100644 index f4d107d..0000000 Binary files a/x64/Debug/EulersProject.tlog/link.read.1.tlog and /dev/null differ diff --git a/x64/Debug/EulersProject.tlog/link.write.1.tlog b/x64/Debug/EulersProject.tlog/link.write.1.tlog deleted file mode 100644 index 01ad415..0000000 Binary files a/x64/Debug/EulersProject.tlog/link.write.1.tlog and /dev/null differ diff --git a/x64/Debug/EulersProject.vcxproj.FileListAbsolute.txt b/x64/Debug/EulersProject.vcxproj.FileListAbsolute.txt deleted file mode 100644 index e69de29..0000000 diff --git a/x64/Debug/Exercises.obj b/x64/Debug/Exercises.obj deleted file mode 100644 index 6bb2f02..0000000 Binary files a/x64/Debug/Exercises.obj and /dev/null differ diff --git a/x64/Debug/Main.obj b/x64/Debug/Main.obj deleted file mode 100644 index d691ece..0000000 Binary files a/x64/Debug/Main.obj and /dev/null differ diff --git a/x64/Debug/vc143.idb b/x64/Debug/vc143.idb deleted file mode 100644 index 4615e8f..0000000 Binary files a/x64/Debug/vc143.idb and /dev/null differ diff --git a/x64/Debug/vc143.pdb b/x64/Debug/vc143.pdb deleted file mode 100644 index ca36d07..0000000 Binary files a/x64/Debug/vc143.pdb and /dev/null differ