Initial commit.

This commit is contained in:
Nicolás A. Ortega 2017-04-02 14:14:09 +02:00
commit 22ff7b923d
No known key found for this signature in database
GPG Key ID: 3D786FB3123FF1DD
8 changed files with 281 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Ignore builds
bin/

50
Makefile Normal file
View File

@ -0,0 +1,50 @@
# 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.
# Compilers
CC=gcc
CXX=g++
JAVAC=javac
# Other commands
RM=rm -rf
# Directories
BINDIR=bin
all: c cpp java
c:
mkdir -p $(BINDIR)
$(CC) src/main.c -o $(BINDIR)/doublesgame-c
cpp:
mkdir -p $(BINDIR)
$(CXX) src/Main.cpp -o $(BINDIR)/doublesgame-cpp
java:
mkdir -p $(BINDIR)
$(JAVAC) src/DoublesGame.java -d $(BINDIR)
.PHONY: clean
clean:
$(RM) $(BINDIR)

15
README.md Normal file
View File

@ -0,0 +1,15 @@
DoublesGame Collection
======================
This is a collection of sources in different languages for [DoublesGame](https://themusicinnoise.net/programs/doublesgame/). Feel free to contribute your own!
Building
--------
There's a Makefile you can use to compile all of the sources or simply one of them. Be aware that you will need the compiler for each and the code may be platform/architecture specific depending on the language.
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.
License
-------
Each file will contain the license given to it by each contributor.

47
src/DoublesGame.java Normal file
View File

@ -0,0 +1,47 @@
/*
* 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.
*/
import java.util.Scanner;
public class DoublesGame {
private static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n = 1;
while(true) {
System.out.print("2^" + n + "=");
int a = Integer.parseInt(in.nextLine());
if(a == 0) {
System.out.println("Goodbye!");
break;
} else if(a != 2 << (n - 1)) {
System.out.println("Wrong answer, try again.");
} else {
System.out.println("Correct!");
++n;
}
}
}
}

44
src/Main.cpp Normal file
View File

@ -0,0 +1,44 @@
/*
* 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.
*/
#include <iostream>
int main(void) {
unsigned int n = 1;
while(true) {
std::cout << "2^" << n << "=";
unsigned int a;
std::cin >> a;
if(a == 0) {
std::cout << "Goodbye!\n";
return 0;
} else if(a not_eq 2 << (n - 1)) {
std::cout << "Wrong answer, try again.\n";
} else {
std::cout << "Correct!\n";
++n;
}
}
}

38
src/doublesgame.py Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/python3
# 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.
import sys
n = 1
while True:
a = int(input("2^{number}=".format(number=n)))
if a is 0:
print("Goodbye!")
break
elif a is not 2 << (n - 1):
print("Wrong answer, try again.")
else:
print("Correct!")
n += 1

42
src/doublesgame.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
# 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
while :
do
printf "2^$n="
read a
if [ $a -eq 0 ]
then
echo "Goodbye!"
break
elif [ $a -ne $((2 << ($n - 1))) ]
then
echo "Wrong answer, try again."
else
echo "Correct!"
let n++
fi
done

43
src/main.c Normal file
View File

@ -0,0 +1,43 @@
/*
* 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.
*/
#include <stdio.h>
int main(void) {
unsigned int n = 1;
while(1) {
printf("2^%u=", n);
unsigned int a;
scanf("%u", &a);
if(a == 0) {
printf("Goodbye!\n");
return 0;
} else if(a != 2 << (n - 1)) {
printf("Wrong answer, try again.\n");
} else {
printf("Correct!\n");
++n;
}
}
}