Use 1 instead of 2, makes the bitshift easier.

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

View File

@ -36,7 +36,7 @@ public class DoublesGame {
if(a == 0) { if(a == 0) {
System.out.println("Goodbye!"); System.out.println("Goodbye!");
break; break;
} else if(a != 2 << (n - 1)) { } else if(a != 1 << n) {
System.out.println("Wrong answer, try again."); System.out.println("Wrong answer, try again.");
} else { } else {
System.out.println("Correct!"); System.out.println("Correct!");

View File

@ -34,7 +34,7 @@ int main(void) {
if(a == 0) { if(a == 0) {
std::cout << "Goodbye!\n"; std::cout << "Goodbye!\n";
return 0; return 0;
} else if(a not_eq 2 << (n - 1)) { } else if(a not_eq 1 << n) {
std::cout << "Wrong answer, try again.\n"; std::cout << "Wrong answer, try again.\n";
} else { } else {
std::cout << "Correct!\n"; std::cout << "Correct!\n";

View File

@ -31,7 +31,7 @@ while True:
if a is 0: if a is 0:
print("Goodbye!") print("Goodbye!")
break break
elif a is not 2 << (n - 1): elif a is not 1 << n:
print("Wrong answer, try again.") print("Wrong answer, try again.")
else: else:
print("Correct!") print("Correct!")

View File

@ -32,7 +32,7 @@ do
then then
echo "Goodbye!" echo "Goodbye!"
break break
elif [ $a -ne $((2 << ($n - 1))) ] elif [ $a -ne $((1 << $n)) ]
then then
echo "Wrong answer, try again." echo "Wrong answer, try again."
else else

View File

@ -33,7 +33,7 @@ int main(void) {
if(a == 0) { if(a == 0) {
printf("Goodbye!\n"); printf("Goodbye!\n");
return 0; return 0;
} else if(a != 2 << (n - 1)) { } else if(a != 1 << n) {
printf("Wrong answer, try again.\n"); printf("Wrong answer, try again.\n");
} else { } else {
printf("Correct!\n"); printf("Correct!\n");