Compare commits

..

10 Commits

Author SHA1 Message Date
Nicolás Ortega Froysa
4256c77217
Changed my e-mail. 2017-08-07 21:10:48 -05:00
Nicolás A. Ortega
b444de05f6
Added new languages to README 2017-06-13 17:11:25 +02:00
Nicolás A. Ortega
98f1072ad0
Added Lua. 2017-06-13 17:10:46 +02:00
Nicolás A. Ortega
9b97d358d6
Added a LISP version too. 2017-06-13 16:52:41 +02:00
Nicolás A. Ortega
596c5ec5d4
Almost have an x86_64 assembly example working. 2017-04-10 21:52:41 +02:00
Nicolás A. Ortega
37fbe91792
Forgot to mention Fortran. 2017-04-10 21:38:51 +02:00
Nicolás A. Ortega
6dbfb0fedb
Use puts. 2017-04-10 15:00:55 +02:00
Nicolás A. Ortega
9c22b0905e
Added Fortran. 2017-04-03 14:28:46 +02:00
Nicolás A. Ortega
88cee02522
Work as an executable. 2017-04-03 14:28:00 +02:00
Nicolás A. Ortega
4ffe20277a
Added Perl. 2017-04-02 14:53:09 +02:00
9 changed files with 257 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
# Ignore builds
bin/
*.o

View File

@ -21,8 +21,11 @@
# distribution.
# Compilers
ASM=as
CC=gcc
CXX=g++
LD=ld
FTR=gfortran
JAVAC=javac
# Other commands
@ -31,7 +34,13 @@ RM=rm -rf
# Directories
BINDIR=bin
all: c cpp java
all: x86-64asm c cpp fortran java
x86-64asm:
mkdir -p $(BINDIR)
$(ASM) -o src/main-x86_64.o src/main-x86_64.asm
$(LD) -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o \
$(BINDIR)/doublesgame-x86_64asm src/main-x86_64.o -lc
c:
mkdir -p $(BINDIR)
@ -41,10 +50,14 @@ cpp:
mkdir -p $(BINDIR)
$(CXX) src/Main.cpp -o $(BINDIR)/doublesgame-cpp
fortran:
mkdir -p $(BINDIR)
$(FTR) src/main.f -o $(BINDIR)/doublesgame-f
java:
mkdir -p $(BINDIR)
$(JAVAC) src/DoublesGame.java -d $(BINDIR)
.PHONY: clean
clean:
$(RM) $(BINDIR)
$(RM) src/*.o

View File

@ -6,7 +6,11 @@ Currently DoublesGame exists in the following languages:
- Bash
- C
- C++
- Common LISP
- Fortran
- Java
- Lua
- Perl
- Python
Building
@ -15,7 +19,7 @@ There's a Makefile you can use to compile all of the sources or simply one of th
Contributing
------------
Do you have another language? Found a bug? Make merge request or send me a patch at [deathsbreed@themusicinnoise.net](mailto:deathsbreed@themusicinnoise.net) and I'll see what I can do. Just make sure to specify a license and copyright statement at the top of the source file, only free software licenses are accepted.
Do you have another language? Found a bug? Make merge request or send me a patch at [nortega@themusicinnoise.net](mailto:nortega@themusicinnoise.net) and I'll see what I can do. Just make sure to specify a license and copyright statement at the top of the source file, only free software licenses are accepted.
License
-------

40
src/doublesgame.lisp Normal file
View File

@ -0,0 +1,40 @@
#|
| Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net> All rights reserved.
| Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
|
| This software is provided 'as-is', without any express or implied
| warranty. In no event will the authors be held liable for any damages
| arising from the use of this software.
|
| Permission is granted to anyone to use this software for any purpose,
| including commercial applications, and to alter it and redistribute it
| freely, subject to the following restrictions:
|
| 1. The origin of this software must not be misrepresented; you must not
| claim that you wrote the original software. If you use this software
| in a product, an acknowledgment in the product documentation would be
| appreciated but is not required.
|
| 2. Altered source versions must be plainly marked as such, and must not be
| misrepresented as being the original software.
|
| 3. This notice may not be removed or altered from any source
| distribution.
|#
(print "Use Ctrl+C to exit.")
(let ((n 1))
(loop
(defvar a)
(format t "~%2^~a=" n)
(setq a (read))
(if (= a (expt 2 n))
(progn
(print "Correct!")
(incf n))
(if (= a 0)
(progn
(print "Goodbye!")
(return nil))
(print "Wrong answer, try again.")))))

39
src/doublesgame.lua Normal file
View File

@ -0,0 +1,39 @@
-- Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net> All rights reserved.
-- Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
--
-- 3. This notice may not be removed or altered from any source
-- distribution.
local n = 1
while(true) do
local a
io.write("2^", n, "=")
a = io.read("*number")
if(a == 0) then
print("Goodbye!")
break
elseif(a == 2 ^ n) then
print("Correct!")
n = n + 1
else
print("Wrong answer, try again.")
end
end

40
src/doublesgame.pl Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/perl
# Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net> All rights reserved.
# Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
$n = 1;
$run = 1;
while($run == 1) {
print "2^$n=";
$a = <>;
if($a == 0) {
print "Goodbye!\n";
$run = 0;
} elsif($a != 1 << $n) {
print "Wrong answer, try again.\n";
} else {
print "Correct!\n";
++$n;
}
}

74
src/main-x86_64.asm Normal file
View File

@ -0,0 +1,74 @@
# Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net> All rights reserved.
# Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source
# distribution.
#
.section .data
equation:
.ascii "2^%d=\0"
query:
.ascii "%d\0"
goodbye:
.ascii "Goodbye!\0"
tryagain:
.ascii "Wrong answer, try again.\0"
correct:
.ascii "Correct!\0"
number:
.int 1
answer:
.int 0
.section .text
.globl _start
_start:
mov number, %rsi
mov $equation, %rdi
call printf
mov $query, %rdi
mov $answer, %rsi
call scanf
cmp $0, answer
je quit
mov number, %rsi
shl $1, %rsi
cmp %rdi, answer
je next
mov $tryagain, %rdi
call puts
jmp _start
next:
mov $correct, %rdi
call puts
mov number, %rax
inc %rax
mov %rax, number
jmp _start
quit:
mov $goodbye, %rdi
call puts
mov $0, %rdi
call exit

View File

@ -31,12 +31,12 @@ int main(void) {
unsigned int a;
scanf("%u", &a);
if(a == 0) {
printf("Goodbye!\n");
puts("Goodbye!");
return 0;
} else if(a != 1 << n) {
printf("Wrong answer, try again.\n");
puts("Wrong answer, try again.");
} else {
printf("Correct!\n");
puts("Correct!");
++n;
}
}

40
src/main.f Normal file
View File

@ -0,0 +1,40 @@
C Copyright (C) 2017 Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net> All rights reserved.
C Author: Ortega Froysa, Nicolás <deathsbreed@themusicinnoise.net>
C
C This software is provided 'as-is', without any express or implied
C warranty. In no event will the authors be held liable for any damages
C arising from the use of this software.
C
C Permission is granted to anyone to use this software for any purpose,
C including commercial applications, and to alter it and redistribute it
C freely, subject to the following restrictions:
C
C 1. The origin of this software must not be misrepresented; you must not
C claim that you wrote the original software. If you use this software
C in a product, an acknowledgment in the product documentation would be
C appreciated but is not required.
C
C 2. Altered source versions must be plainly marked as such, and must not be
C misrepresented as being the original software.
C
C 3. This notice may not be removed or altered from any source
C distribution.
program doublesgame
integer :: a,n = 1
logical :: run = .TRUE.
do while(run)
write(*,*) '2^', n, '='
read(*,*) a
if(a .EQ. 0) then
write(*,*) "Goodbye!"
run = .FALSE.
elseif(a .NE. 2 ** n) then
write(*,*) "Wrong answer, try again."
else
write(*,*) "Correct!"
n = n + 1
endif
enddo
end program doublesgame