Compare commits
10 Commits
3dd52a9c70
...
4256c77217
Author | SHA1 | Date | |
---|---|---|---|
|
4256c77217 | ||
|
b444de05f6 | ||
|
98f1072ad0 | ||
|
9b97d358d6 | ||
|
596c5ec5d4 | ||
|
37fbe91792 | ||
|
6dbfb0fedb | ||
|
9c22b0905e | ||
|
88cee02522 | ||
|
4ffe20277a |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
# Ignore builds
|
# Ignore builds
|
||||||
bin/
|
bin/
|
||||||
|
*.o
|
||||||
|
17
Makefile
17
Makefile
@ -21,8 +21,11 @@
|
|||||||
# distribution.
|
# distribution.
|
||||||
|
|
||||||
# Compilers
|
# Compilers
|
||||||
|
ASM=as
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CXX=g++
|
CXX=g++
|
||||||
|
LD=ld
|
||||||
|
FTR=gfortran
|
||||||
JAVAC=javac
|
JAVAC=javac
|
||||||
|
|
||||||
# Other commands
|
# Other commands
|
||||||
@ -31,7 +34,13 @@ RM=rm -rf
|
|||||||
# Directories
|
# Directories
|
||||||
BINDIR=bin
|
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:
|
c:
|
||||||
mkdir -p $(BINDIR)
|
mkdir -p $(BINDIR)
|
||||||
@ -41,10 +50,14 @@ cpp:
|
|||||||
mkdir -p $(BINDIR)
|
mkdir -p $(BINDIR)
|
||||||
$(CXX) src/Main.cpp -o $(BINDIR)/doublesgame-cpp
|
$(CXX) src/Main.cpp -o $(BINDIR)/doublesgame-cpp
|
||||||
|
|
||||||
|
fortran:
|
||||||
|
mkdir -p $(BINDIR)
|
||||||
|
$(FTR) src/main.f -o $(BINDIR)/doublesgame-f
|
||||||
|
|
||||||
java:
|
java:
|
||||||
mkdir -p $(BINDIR)
|
mkdir -p $(BINDIR)
|
||||||
$(JAVAC) src/DoublesGame.java -d $(BINDIR)
|
$(JAVAC) src/DoublesGame.java -d $(BINDIR)
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(BINDIR)
|
$(RM) src/*.o
|
||||||
|
@ -6,7 +6,11 @@ Currently DoublesGame exists in the following languages:
|
|||||||
- Bash
|
- Bash
|
||||||
- C
|
- C
|
||||||
- C++
|
- C++
|
||||||
|
- Common LISP
|
||||||
|
- Fortran
|
||||||
- Java
|
- Java
|
||||||
|
- Lua
|
||||||
|
- Perl
|
||||||
- Python
|
- Python
|
||||||
|
|
||||||
Building
|
Building
|
||||||
@ -15,7 +19,7 @@ There's a Makefile you can use to compile all of the sources or simply one of th
|
|||||||
|
|
||||||
Contributing
|
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
|
License
|
||||||
-------
|
-------
|
||||||
|
40
src/doublesgame.lisp
Normal file
40
src/doublesgame.lisp
Normal 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
39
src/doublesgame.lua
Normal 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
40
src/doublesgame.pl
Executable 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
74
src/main-x86_64.asm
Normal 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
|
@ -31,12 +31,12 @@ int main(void) {
|
|||||||
unsigned int a;
|
unsigned int a;
|
||||||
scanf("%u", &a);
|
scanf("%u", &a);
|
||||||
if(a == 0) {
|
if(a == 0) {
|
||||||
printf("Goodbye!\n");
|
puts("Goodbye!");
|
||||||
return 0;
|
return 0;
|
||||||
} else if(a != 1 << n) {
|
} else if(a != 1 << n) {
|
||||||
printf("Wrong answer, try again.\n");
|
puts("Wrong answer, try again.");
|
||||||
} else {
|
} else {
|
||||||
printf("Correct!\n");
|
puts("Correct!");
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
src/main.f
Normal file
40
src/main.f
Normal 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
|
Loading…
Reference in New Issue
Block a user