diff options
author | mjfernez <mjfernez@gmail.com> | 2021-10-12 20:18:28 -0400 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2021-10-12 20:18:28 -0400 |
commit | 3cf128d6da667d00bb5bb659413ea55a98a02aff (patch) | |
tree | 12eb90997dfa63d65fe6da714626271272342320 | |
parent | 009ce017d99a8deb2089438381c273e8f3ea3b67 (diff) | |
download | Project_Euler_Solutions-3cf128d6da667d00bb5bb659413ea55a98a02aff.tar.gz |
38 files changed, 507 insertions, 130 deletions
@@ -1,104 +1 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ +**/.gdb_history diff --git a/01-Multiples-of-3-and-5/asm/Makefile b/01-Multiples-of-3-and-5/asm/Makefile new file mode 100644 index 0000000..c34d1a2 --- /dev/null +++ b/01-Multiples-of-3-and-5/asm/Makefile @@ -0,0 +1,6 @@ +euler1: euler1.o + gcc euler1.o -o euler1 +euler1.o: euler1.asm + nasm -w+all -f elf64 -g -F stabs euler1.asm +clean: + rm -f euler1 euler1.o diff --git a/01-Multiples-of-3-and-5/asm/euler1 b/01-Multiples-of-3-and-5/asm/euler1 Binary files differnew file mode 100755 index 0000000..278476a --- /dev/null +++ b/01-Multiples-of-3-and-5/asm/euler1 diff --git a/01-Multiples-of-3-and-5/asm/euler1.asm b/01-Multiples-of-3-and-5/asm/euler1.asm new file mode 100644 index 0000000..9541295 --- /dev/null +++ b/01-Multiples-of-3-and-5/asm/euler1.asm @@ -0,0 +1,42 @@ +extern printf +SECTION .data +flag: db "%d",10,0 ; "%d\n\0" + +SECTION .text + global main + +main: + push rbp ; set up stack + mov rbp, rsp + xor rax, rax ; start at multiple (i = 0) + mov r11, 0 ; sum = 0 + mov r12, 1000 ; max = 1000 +.loop xor rdx, rdx ; clear rdx (remainder) + push rax ; save rax + mov rcx, 5 ; divisible by 5 + div rcx ; divide rdx:rax/rcx + cmp rdx, 0 ; compare only remainder + jz .sum ; if r = 0 , add to sum + xor rdx,rdx ; clear rdx + mov rax, QWORD [rsp] ; reload rax + mov rcx, 3 ; divisible by 3 + div rcx ; divide rdx:rax/rcx + cmp rdx, 0 ; compare only remainder + jnz .next ; if r = 0 , add to sum + +.sum add r11, QWORD [rsp] ; add to sum register + +.next pop rax ; return rax value from stack to be inc + inc rax ; i++ + cmp rax, r12 ; while rax < r12 (1000) + jl .loop ; repeat + + mov rdi, flag ; arg 1 (format) + mov rsi, r11 ; arg 2 (value) + mov rax, 0 ; no xmm registers + call printf wrt ..plt + pop rbp + + mov rax, 0 + ret + diff --git a/01-Multiples-of-3-and-5/asm/euler1.o b/01-Multiples-of-3-and-5/asm/euler1.o Binary files differnew file mode 100644 index 0000000..b45c7c1 --- /dev/null +++ b/01-Multiples-of-3-and-5/asm/euler1.o diff --git a/01-Multiples-of-3-and-5/euler1 b/01-Multiples-of-3-and-5/euler1 Binary files differindex 585d380..93718c8 100644..100755 --- a/01-Multiples-of-3-and-5/euler1 +++ b/01-Multiples-of-3-and-5/euler1 diff --git a/01-Multiples-of-3-and-5/euler1.c b/01-Multiples-of-3-and-5/euler1.c index d89956e..ff24a08 100644 --- a/01-Multiples-of-3-and-5/euler1.c +++ b/01-Multiples-of-3-and-5/euler1.c @@ -3,11 +3,11 @@ //Problem 1: multiples of 3 and 5 int main(){ int max = 1000; - int i; double sum; + int i, sum = 0; - for (i=0;i<max; i++) - if(i%3 == 0 || i%5==0) - sum+= (double) i; + for (i; i<max; i++) + if (!(i%3) || !(i%5)) + sum+=i; - printf("%f\n", sum); + printf("%d\n", sum); } diff --git a/02-Even-Fibonacci-numbers/asm/Makefile b/02-Even-Fibonacci-numbers/asm/Makefile new file mode 100644 index 0000000..479e773 --- /dev/null +++ b/02-Even-Fibonacci-numbers/asm/Makefile @@ -0,0 +1,6 @@ +fib: fib.o + gcc fib.o -o fib +fib.o: fib.asm + nasm -w+all -f elf64 -g -F stabs fib.asm +clean: + rm -f fib fib.o diff --git a/02-Even-Fibonacci-numbers/asm/fib b/02-Even-Fibonacci-numbers/asm/fib Binary files differnew file mode 100755 index 0000000..662eb0a --- /dev/null +++ b/02-Even-Fibonacci-numbers/asm/fib diff --git a/02-Even-Fibonacci-numbers/asm/fib.asm b/02-Even-Fibonacci-numbers/asm/fib.asm new file mode 100644 index 0000000..600a542 --- /dev/null +++ b/02-Even-Fibonacci-numbers/asm/fib.asm @@ -0,0 +1,43 @@ +; By considering the terms in the Fibonacci sequence whose values do not exceed four million, +; find the sum of the even-valued terms. +extern printf +SECTION .data +flag: db "%d",10,0 ; "%d\n\0" + +SECTION .text + global main + +main: + push rbp ; set up stack + mov rbp, rsp + mov rax, 1 ; start at fib_1 = 1 + push rax ; push first term of fib onto stack + mov r11, 0 ; sum = 0 + mov r12, 0x3D0900 ; max = 4000000, this is < 2^64 + ; so we only need one register + +.loop xor rdx, rdx ; clear rdx (remainder) + push rax ; push current term on the stack + mov rcx, 2 ; divisible by 2 + div rcx ; divide rdx:rax/rcx + cmp rdx, 0 ; compare only remainder + jz .sum ; if r = 0 , add to sum + jmp .next ; else skip + +.sum add r11, QWORD [rsp] ; add latest term to sum register + +.next mov rax, QWORD [rsp] ; reload rax to current term + add rax, QWORD [rsp+8] ; add last term to current term + cmp rax, r12 ; while rax < r12 (4 mil) + jl .loop + + mov rdi, flag ; arg 1 (format) + mov rsi, r11 ; arg 2 (value) + mov rax, 0 ; no xmm registers + call printf wrt ..plt + mov rsp, rbp ; reset to the top of the stack + pop rbp + + mov rax, 0 + ret + diff --git a/02-Even-Fibonacci-numbers/asm/fib.o b/02-Even-Fibonacci-numbers/asm/fib.o Binary files differnew file mode 100644 index 0000000..2a4eadf --- /dev/null +++ b/02-Even-Fibonacci-numbers/asm/fib.o diff --git a/02-Even-Fibonacci-numbers/fib b/02-Even-Fibonacci-numbers/fib Binary files differindex e9b1b3b..e9b1b3b 100644..100755 --- a/02-Even-Fibonacci-numbers/fib +++ b/02-Even-Fibonacci-numbers/fib diff --git a/03-Largest-Prime-Factor/asm/Makefile b/03-Largest-Prime-Factor/asm/Makefile new file mode 100644 index 0000000..054301c --- /dev/null +++ b/03-Largest-Prime-Factor/asm/Makefile @@ -0,0 +1,6 @@ +lpf: lpf.o + gcc lpf.o -o lpf +lpf.o: lpf.asm + nasm -w+all -f elf64 -g -F stabs lpf.asm +clean: + rm -f lpf lpf.o diff --git a/03-Largest-Prime-Factor/asm/lpf b/03-Largest-Prime-Factor/asm/lpf Binary files differnew file mode 100755 index 0000000..aee8383 --- /dev/null +++ b/03-Largest-Prime-Factor/asm/lpf diff --git a/03-Largest-Prime-Factor/asm/lpf.asm b/03-Largest-Prime-Factor/asm/lpf.asm new file mode 100644 index 0000000..3e67ed3 --- /dev/null +++ b/03-Largest-Prime-Factor/asm/lpf.asm @@ -0,0 +1,45 @@ +; What is the largest prime factor of the number 600851475143 ? +extern printf +SECTION .data +flag: db "%d",10,0 ; "%d\n\0" + +SECTION .text + global main + +main: + push rbp ; set up stack + mov rbp, rsp + + + mov rcx, 2 ; smallest prime factor: 2 + mov rax, 0x8BE589EAC7 ; target = 600851475143 + +.loop xor rdx, rdx ; clear rdx (remainder) + push rax + div rcx ; divide rdx:rax/rcx + cmp rdx, 0 ; compare only remainder + jnz .next ; if r = 0 , its a factor + ; we already divided the number so + ; we just need to save the value in rax + ; as the new number to factorize + add rsp, 8 ; delete the old + push rax + mov rcx, 1 ; reset the counter (normally would start at 2, + ; but we increment anyway +.next pop rax ; refresh value + inc rcx ; factor ++ + cmp rax, rcx ; while rax > rcx number > factor + ; i.e. not a prime factor + jg .loop + + mov rdi, flag ; arg 1 (format) + mov rsi, rcx ; arg 2 (value) + mov rax, 0 ; no xmm registers + call printf wrt ..plt + + mov rsp, rbp ; reset to the top of the stack + pop rbp + + mov rax, 0 + ret + diff --git a/03-Largest-Prime-Factor/asm/lpf.o b/03-Largest-Prime-Factor/asm/lpf.o Binary files differnew file mode 100644 index 0000000..df0449d --- /dev/null +++ b/03-Largest-Prime-Factor/asm/lpf.o diff --git a/03-Largest-Prime-Factor/largestprime b/03-Largest-Prime-Factor/largestprime Binary files differindex c2afe6f..c2afe6f 100644..100755 --- a/03-Largest-Prime-Factor/largestprime +++ b/03-Largest-Prime-Factor/largestprime diff --git a/04-Largest-Palindrome-Product/asm/Makefile b/04-Largest-Palindrome-Product/asm/Makefile new file mode 100644 index 0000000..53b33b2 --- /dev/null +++ b/04-Largest-Palindrome-Product/asm/Makefile @@ -0,0 +1,6 @@ +palindrome: palindrome.o + gcc palindrome.o -o palindrome +palindrome.o: palindrome.asm + nasm -w+all -f elf64 -g -F stabs palindrome.asm +clean: + rm -f palindrome palindrome.o diff --git a/04-Largest-Palindrome-Product/asm/palindrome b/04-Largest-Palindrome-Product/asm/palindrome Binary files differnew file mode 100755 index 0000000..3f75c67 --- /dev/null +++ b/04-Largest-Palindrome-Product/asm/palindrome diff --git a/04-Largest-Palindrome-Product/asm/palindrome.asm b/04-Largest-Palindrome-Product/asm/palindrome.asm new file mode 100644 index 0000000..03cd724 --- /dev/null +++ b/04-Largest-Palindrome-Product/asm/palindrome.asm @@ -0,0 +1,83 @@ +; Find the largest palindrome made from the product of two 3-digit numbers. + +extern printf +SECTION .data +flag: db "%d",10,0 ; "%d\n\0" + +SECTION .text + global main + global is_palindrome + +is_palindrome: +; check if the product in rax is a palindrome + + push rax ; save the value + xor r14, r14 ; using this as a string length counter +.div: xor rdx, rdx ; clear operand for div + div r12 ; rdx:rax / 10 + add rdx, 0x30 ; digit is in remainder, add ascii 0 + push rdx + inc r14 + cmp rax, 0 + jnz .div + +; Cheating a bit here. Highest product of two 3 digit numbers will +; not exceed 6 digits. We assume only three comparisons need to made +; 5 digit numbers are excluded outright + + cmp r14, 6 + jne main.nexti ; return + mov rax, [rsp] + mov rdx, [rbp-0x18] ; at this point, original rbp, ret and rax are + cmp rax, rdx ; on the stack, so skip three qwords (64bits) + jne main.nexti + mov rax, [rsp+8] + mov rdx, [rbp-0x20] + cmp rax, rdx + jne main.nexti + mov rax, [rsp+16] + mov rdx, [rbp-0x28] + cmp rax, rdx + jne main.nexti + ; if you made it here, rax is a palindrome! + mov rsp, rbp ; reset stack back to the first variable + sub rsp, 16 ; first 8 bytes is the return call + pop rax + ret + +main: + push rbp ; set up stack + mov rbp, rsp + mov r11, 0x3E7 ; j=999 + mov r12, 0xA ; for division testing later + xor r13, r13 ; current max palindrome (0) +; check products for three digit numbers (starting with highest) +.loopj mov rcx, 0x3E7 ; setup counter two (i=999) + +.loopi xor rdx, rdx ; clear operand for mul + mov rax, r11 ; operand for mul + mul rcx ; rdx:rax = rax * rcx (j * i) + ; hint this won't overflow + call is_palindrome + ; if you made it here, rax is a palindrome! + cmp rax, r13 ; if rax is not bigger than the current max + jl .nexti ; next loop + mov r13, rax ; otherwise, update value + +.nexti: mov rsp, rbp ; reset stack (if needed) + loopnz .loopi ; i = 0, decrement j and restart + + dec r11 ; j-- + jnz .loopj + +.print mov rdi, flag ; arg 1 (format) + mov rsi, r13 ; arg 2 + mov rax, 0 ; no xmm registers + call printf wrt ..plt + + mov rsp, rbp ; reset to the top of the stack + pop rbp + + mov rax, 0 + ret + diff --git a/04-Largest-Palindrome-Product/asm/palindrome.o b/04-Largest-Palindrome-Product/asm/palindrome.o Binary files differnew file mode 100644 index 0000000..6f1d9da --- /dev/null +++ b/04-Largest-Palindrome-Product/asm/palindrome.o diff --git a/04-Largest-Palindrome-Product/palindrome b/04-Largest-Palindrome-Product/palindrome Binary files differindex f4d607f..f4d607f 100644..100755 --- a/04-Largest-Palindrome-Product/palindrome +++ b/04-Largest-Palindrome-Product/palindrome diff --git a/05-Smallest-Multiple/asm/Makefile b/05-Smallest-Multiple/asm/Makefile new file mode 100644 index 0000000..3ae43fc --- /dev/null +++ b/05-Smallest-Multiple/asm/Makefile @@ -0,0 +1,6 @@ +smallmult: smallmult.o + gcc smallmult.o -o smallmult +smallmult.o: smallmult.asm + nasm -w+all -f elf64 -g -F stabs smallmult.asm +clean: + rm -f smallmult smallmult.o diff --git a/05-Smallest-Multiple/asm/smallmult b/05-Smallest-Multiple/asm/smallmult Binary files differnew file mode 100755 index 0000000..af65d5a --- /dev/null +++ b/05-Smallest-Multiple/asm/smallmult diff --git a/05-Smallest-Multiple/asm/smallmult.asm b/05-Smallest-Multiple/asm/smallmult.asm new file mode 100644 index 0000000..c154ff3 --- /dev/null +++ b/05-Smallest-Multiple/asm/smallmult.asm @@ -0,0 +1,44 @@ +; 2520 is the smallest number that can be divided by each of the numbers +; from 1 to 10 without any remainder. +; What is the smallest positive number that is evenly divisible by all +; of the numbers from 1 to 20? + +extern printf +SECTION .data +flag: db "%d",10,0 ; "%d\n\0" + +SECTION .text + global main + global is_divisible + +main: + push rbp ; set up stack + mov rbp, rsp + + mov rax, 2520 ; value to start at (given) + mov rcx, 20 ; divisor (counting down) +.loop add rax, rcx + push rcx +.isdiv xor rdx, rdx ; clear rdx for div + push rax ; save rax before dividing + div rcx ; rdx:rax/rcx = rax remainder rdx + pop rax ; reload rax to be divided again + cmp rdx, 0 ; the number was divisible, keep going + loopz .isdiv ; loop exits if rdx is non zero OR rcx is 0 + cmp rcx, 0 ; if rcx = 0, it means it looped 20 to 1 w/o + jz .print ; any remainders, that's our number! + ; if you get here, number couldn't be evenly divided by all numbers + pop rcx + jmp .loop + + + +.print: mov rdi, flag ; arg 1 (format) + mov rsi, rax ; arg 2 (value) + mov rax, 0 ; no xmm registers + call printf wrt ..plt + pop rbp + + mov rax, 0 + ret + diff --git a/05-Smallest-Multiple/asm/smallmult.o b/05-Smallest-Multiple/asm/smallmult.o Binary files differnew file mode 100644 index 0000000..d2c9fe0 --- /dev/null +++ b/05-Smallest-Multiple/asm/smallmult.o diff --git a/05-Smallest-Multiple/smallmult b/05-Smallest-Multiple/smallmult Binary files differindex 5f4e692..5f4e692 100644..100755 --- a/05-Smallest-Multiple/smallmult +++ b/05-Smallest-Multiple/smallmult diff --git a/06-Sum-Square-Difference/asm/Makefile b/06-Sum-Square-Difference/asm/Makefile new file mode 100644 index 0000000..68e7f4f --- /dev/null +++ b/06-Sum-Square-Difference/asm/Makefile @@ -0,0 +1,6 @@ +sumsq: sumsq.o + gcc sumsq.o -o sumsq +sumsq.o: sumsq.asm + nasm -w+all -f elf64 -g -F stabs sumsq.asm +clean: + rm -f sumsq sumsq.o diff --git a/06-Sum-Square-Difference/asm/sumsq b/06-Sum-Square-Difference/asm/sumsq Binary files differnew file mode 100755 index 0000000..d282ab2 --- /dev/null +++ b/06-Sum-Square-Difference/asm/sumsq diff --git a/06-Sum-Square-Difference/asm/sumsq.asm b/06-Sum-Square-Difference/asm/sumsq.asm new file mode 100644 index 0000000..cc9295a --- /dev/null +++ b/06-Sum-Square-Difference/asm/sumsq.asm @@ -0,0 +1,49 @@ +; Find the difference between (1+2+3+...+100)^2 and (1^2+2^2+3^2+...+100^2) +; I used another math trick here: +; The sum up to a number can be found using Gauss' Trick: +; 1 + 2 + 3 + ... + 10 -> (1+9) + (2+8) + (3+7) + (4+6) + 10 + 5 -> 5*10 +5 +; In general : (n/2)(n+1) + +extern printf +SECTION .data +flag: db "%d",10,0 ; "%d\n\0" + +SECTION .text + global main + global is_divisible + +main: + push rbp ; set up stack + mov rbp, rsp + + ; first square of sum (1+2+...100)^2 + mov rax, 50 ; sum = n/2 + mov rcx, 101 ; * (n + 1) + mul rcx + mul rax ; square it + push rax ; save it + + ; now sum the squares (1^2+2^2 ...) no short cut this time + xor r11, r11 ; This will store the sum, rcx will b n, + ; rax is just used to multiply + mov rcx, 0 ; n = 0, we add one first + +.loop inc rcx ; see? told you :) + mov rax, rcx ; move into multiply register + mul rax ; multiply by itself + add r11, rax ; add to the sum + cmp rcx, 100 + jne .loop + + pop rax ; sum of the squares is on the stack + sub rax, r11 ; take the difference, rax - r11 + ; square of the sum is bigger +.print mov rdi, flag ; arg 1 (format) + mov rsi, rax ; arg 2 (value) + mov rax, 0 ; no xmm registers + call printf wrt ..plt + pop rbp + + mov rax, 0 + ret + diff --git a/06-Sum-Square-Difference/asm/sumsq.o b/06-Sum-Square-Difference/asm/sumsq.o Binary files differnew file mode 100644 index 0000000..9b0a44b --- /dev/null +++ b/06-Sum-Square-Difference/asm/sumsq.o diff --git a/06-Sum-Square-Difference/sumsq b/06-Sum-Square-Difference/sumsq Binary files differindex 8f8aa03..8f8aa03 100644..100755 --- a/06-Sum-Square-Difference/sumsq +++ b/06-Sum-Square-Difference/sumsq diff --git a/07-10001st-Prime/asm/Makefile b/07-10001st-Prime/asm/Makefile new file mode 100644 index 0000000..035c695 --- /dev/null +++ b/07-10001st-Prime/asm/Makefile @@ -0,0 +1,6 @@ +prime: prime.o + gcc prime.o -o prime +prime.o: prime.asm + nasm -w+all -f elf64 -g -F stabs prime.asm +clean: + rm -f prime prime.o diff --git a/07-10001st-Prime/asm/prime b/07-10001st-Prime/asm/prime Binary files differnew file mode 100755 index 0000000..e7318f8 --- /dev/null +++ b/07-10001st-Prime/asm/prime diff --git a/07-10001st-Prime/asm/prime.asm b/07-10001st-Prime/asm/prime.asm new file mode 100644 index 0000000..078db26 --- /dev/null +++ b/07-10001st-Prime/asm/prime.asm @@ -0,0 +1,24 @@ +; What is the 10 001st prime number? + +extern printf +SECTION .data +flag: db "%d",10,0 ; "%d\n\0" + +SECTION .text + global main + global is_divisible + +main: + push rbp ; set up stack + mov rbp, rsp + + +.print mov rdi, flag ; arg 1 (format) + mov rsi, rax ; arg 2 (value) + mov rax, 0 ; no xmm registers + call printf wrt ..plt + pop rbp + + mov rax, 0 + ret + diff --git a/07-10001st-Prime/asm/prime.o b/07-10001st-Prime/asm/prime.o Binary files differnew file mode 100644 index 0000000..7c52424 --- /dev/null +++ b/07-10001st-Prime/asm/prime.o @@ -1,21 +1,122 @@ -MIT License - -Copyright (c) 2018 Mike - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. + @@ -28,3 +28,10 @@ Please re-write my solutions in another language. Or if you can't, at least go a retype each line, renaming the variables so they make sense to you (I was kind of deliberately cryptic). Or even better, write a prettier solution! Some these are kind of inelegant. They get the job done but... + + +* UPDATE: now with assembly (NASM) examples! +I did cheat a bit by stealing C's printf function since writing numbers can be a pain. +See the Makefile for each example for instructions on how to build. I'm still new to +assembly so the code is not optimized, but I tried to opt for more readability where I +could
\ No newline at end of file |