From 22ff7b923dd5476ca4be9fec1d3e574c77ddc31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega?= Date: Sun, 2 Apr 2017 14:14:09 +0200 Subject: [PATCH] Initial commit. --- .gitignore | 2 ++ Makefile | 50 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 15 +++++++++++++ src/DoublesGame.java | 47 +++++++++++++++++++++++++++++++++++++++++ src/Main.cpp | 44 ++++++++++++++++++++++++++++++++++++++ src/doublesgame.py | 38 +++++++++++++++++++++++++++++++++ src/doublesgame.sh | 42 +++++++++++++++++++++++++++++++++++++ src/main.c | 43 +++++++++++++++++++++++++++++++++++++ 8 files changed, 281 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 src/DoublesGame.java create mode 100644 src/Main.cpp create mode 100755 src/doublesgame.py create mode 100755 src/doublesgame.sh create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c45d290 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Ignore builds +bin/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9a6250d --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +# Copyright (C) 2017 Ortega Froysa, Nicolás All rights reserved. +# Author: Ortega Froysa, Nicolás +# +# 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) diff --git a/README.md b/README.md new file mode 100644 index 0000000..5511380 --- /dev/null +++ b/README.md @@ -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. diff --git a/src/DoublesGame.java b/src/DoublesGame.java new file mode 100644 index 0000000..a58c7b7 --- /dev/null +++ b/src/DoublesGame.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2017 Ortega Froysa, Nicolás All rights reserved. + * Author: Ortega Froysa, Nicolás + * + * 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; + } + } + } +} diff --git a/src/Main.cpp b/src/Main.cpp new file mode 100644 index 0000000..2c9f432 --- /dev/null +++ b/src/Main.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2017 Ortega Froysa, Nicolás All rights reserved. + * Author: Ortega Froysa, Nicolás + * + * 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 + +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; + } + } +} diff --git a/src/doublesgame.py b/src/doublesgame.py new file mode 100755 index 0000000..fab62a6 --- /dev/null +++ b/src/doublesgame.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 + +# Copyright (C) 2017 Ortega Froysa, Nicolás All rights reserved. +# Author: Ortega Froysa, Nicolás +# +# 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 diff --git a/src/doublesgame.sh b/src/doublesgame.sh new file mode 100755 index 0000000..fed6865 --- /dev/null +++ b/src/doublesgame.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright (C) 2017 Ortega Froysa, Nicolás All rights reserved. +# Author: Ortega Froysa, Nicolás +# +# 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 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..de41a5c --- /dev/null +++ b/src/main.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 Ortega Froysa, Nicolás All rights reserved. + * Author: Ortega Froysa, Nicolás + * + * 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 + +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; + } + } +}