Compare commits

..

10 Commits

Author SHA1 Message Date
deadvey
46388bc302 started js port 2024-11-17 15:50:41 +00:00
deadvey
98f616b5a2 readme 2024-11-15 16:23:45 +00:00
deadvey
8b2f9a291a s&m 2024-11-15 16:23:23 +00:00
deadvey
0e4cd2427a bye 2024-11-15 11:56:48 +00:00
deadvey
8db5c9c7d0 moved from todo to current features in readme 2024-11-15 11:38:47 +00:00
deadvey
1f2ed35c44 two's compliment 2024-11-15 11:38:15 +00:00
deadvey
acff092e30 bug: for some reason the binary adition question included the 0b on one occassion, dunno why, must investigate 2024-11-15 01:06:56 +00:00
deadvey
8c9d854f16 more formatting 2024-11-15 00:12:15 +00:00
deadvey
4419116901 readme shit 2024-11-15 00:04:29 +00:00
deadvey
f835ddbc7e readme 2024-11-14 23:53:25 +00:00
3 changed files with 90 additions and 20 deletions

View File

@@ -8,12 +8,13 @@ https://www.pgonline.co.uk/resources/computer-science/a-level-ocr/ocr-a-level-te
- Conversions between bases (integers)<br/> - Conversions between bases (integers)<br/>
- Binary addition<br/> - Binary addition<br/>
- Floating point binary to denery conversion<br/> - Floating point binary to denery conversion<br/>
# TODO
- Two's complement<br/> - Two's complement<br/>
- Sign and magnitude<br/> - Sign and magnitude<br/>
- Negative binary<br/>
# TODO
- Complex binary* <br/> - Complex binary* <br/>
# Why the fuck is this a thing? # Why the fuck is this a thing?
I was fucking revision my fucking as levels and I wanted a program to auto make binary and other bases questions up so I could just rattle through them so yeah. I was fucking revision my fucking as levels and I wanted a program to auto make binary and other bases questions up so I could just rattle through them so yeah.<br/>
Also the fucking code is shit as fuck, like barely any comments, imma do that at some point, just can't be fucking arsed to atm<br/>
I made this while I should've been listening to class so don't tell my teahcer<br/>

1
bases-game.js Normal file
View File

@@ -0,0 +1 @@
Math.random

View File

@@ -1,6 +1,11 @@
print("") print("")
import random import random
score = 0
answered = 0
def correct():
global score
score+=1
print("\nCorrect!")
while True: while True:
''' '''
Conversion ----- 2 -> 10 Conversion ----- 2 -> 10
@@ -12,12 +17,75 @@ while True:
Binary Addition Binary Addition
Floating point binary Floating point binary
Twos compliment, Sign & Magnitude, Negative binary, Complex binary Twos compliment,
Sign & Magnitude,
''' '''
type_int = random.randint(0,2) type_int = random.randint(0,4)
if type_int == 4:
start_base = random.randint(0,1)
number_int = random.randint(0,128)
number_bin = format(number_int, '#010b')[2:]
if random.randint(0,1) == 1: # 50/50 chance of being negative
number_int = 0 - number_int
number_bin = '1' + number_bin[1:]
if start_base == 0: # Binary -> Denery
print("\nWhat is this Sign and Magnitude base 2 number in base 10?\n")
print(number_bin)
print("")
print("-")
print("|100")
print("||10")
print("|||1")
print("||||")
print("VVVV")
answer = str(int(number_int))
elif start_base == 1: # Denery -> Binary
print("\nWhat is this base 10 number in Sign and Magnitude base 2?\n")
print(number_int)
print("")
print("-")
print("|64")
print("||32")
print("|||16")
print("||||8421")
print("||||||||")
print("VVVVVVVV")
answer = str(int(number_bin))
attempt = input()
if int(attempt) == int(answer):
correct()
else:
print(f"No, the answer was {answer}")
if type_int == 3:
start_base = random.randint(0,1)
positive_int = random.randint(0,127)
negative_int = 0 - positive_int
positive_bin = format(positive_int, '#010b')[2:]
negative_bin = ""
for x in positive_bin:
if x == "0":
negative_bin += "1"
else:
negative_bin += "0"
negative_bin = bin(int(negative_bin,2) + 1)[2:]
if (start_base == 0): # Binary -> Denery
print("\nWhat does this two's compliment number represent in base 10?\n")
print(negative_bin)
answer = str(negative_int)
elif (start_base == 1): # Denery -> Binary
print("\nWhat does this negative number represent in base 2 (two's compliment)\n")
print(negative_int)
answer = str(negative_bin)
attempt = input()
if attempt == answer:
correct()
else:
print(f"No, the answer was {answer}")
if type_int == 2: if type_int == 2:
print("What is this binary floating point number in denery?") print("What is this binary floating point number in denery?\n")
int_length = random.randint(0,7) int_length = random.randint(0,7)
decimal_length = random.randint(1,7) decimal_length = random.randint(1,7)
answer = float(random.randint(0,2**int_length)) answer = float(random.randint(0,2**int_length))
@@ -32,15 +100,15 @@ while True:
print(start_int+start_frac," exp:", exponent) print(start_int+start_frac," exp:", exponent)
attempt = input() attempt = input()
if float(attempt) == answer: if float(attempt) == answer:
print("Correct") correct()
else: else:
print(f"No, the answer was {answer}") print(f"No, the answer was {answer}")
if type_int == 1: if type_int == 1:
answer_in_bin_or_den = random.randint(0,1) answer_in_bin_or_den = random.randint(0,0)
if answer_in_bin_or_den == 1: if answer_in_bin_or_den == 1:
print("Answer in Base 10") print("Answer in Base 10\n")
if answer_in_bin_or_den == 0: if answer_in_bin_or_den == 0:
print("Answer in Base 2") print("Answer in Base 2\n")
numbers_to_add = random.randint(2,2) numbers_to_add = random.randint(2,2)
numbers = [] numbers = []
answer = 0 answer = 0
@@ -57,12 +125,12 @@ while True:
attempt = input() attempt = input()
if answer_in_bin_or_den == 1: if answer_in_bin_or_den == 1:
if int(attempt) == answer: if int(attempt) == answer:
print("Correct") correct()
else: else:
print(f"No, the answer was {answer}") print(f"No, the answer was {answer}")
if answer_in_bin_or_den == 0: if answer_in_bin_or_den == 0:
if str(bin(int(attempt,2)))[2:] == str(bin(answer))[2:]: if str(bin(int(attempt,2)))[2:] == str(bin(answer))[2:]:
print("Correct") correct()
else: else:
print(f"No, the answer was {bin(answer)}") print(f"No, the answer was {bin(answer)}")
if type_int == 0: if type_int == 0:
@@ -126,18 +194,18 @@ while True:
attempt = input() attempt = input()
if final_base == 16: if final_base == 16:
if str(hex(int(attempt,16)))[2:] == str(hex(start_number))[2:]: if str(hex(int(attempt,16)))[2:] == str(hex(start_number))[2:]:
print("Correct") correct()
else: else:
print(f"No, the answer was {hex(int(start_number))[2:]}") print(f"No, the answer was {hex(int(start_number))[2:]}")
if final_base == 10: if final_base == 10:
if attempt == str(int(start_number)): if str(int(attempt)) == str(int(start_number)):
print("Correct") correct()
else: else:
print(f"No, the answer was {int(start_number)}") print(f"No, the answer was {int(start_number)}")
if final_base == 2: if final_base == 2:
if str(bin(int(attempt,2)))[2:] == str(bin(start_number))[2:]: if str(bin(int(attempt,2)))[2:] == str(bin(start_number))[2:]:
print("Correct") correct()
else: else:
print(f"No, the answer was {bin(start_number)[2:]}") print(f"No, the answer was {bin(start_number)[2:]}")
answered+=1
print("------------------------------------") print(f"\nScore: {score}/{answered}\n------------------------------------\n")