Ad
Matrix
Code
Diff
  • class OperationError(Exception):
        def __init__(self, message):            
            super().__init__(message)
    
    
    def matrix(matrix=list, operation=str, location=tuple, writedata=None):
        try:
            if operation == "read":
                return matrix[location[0]][location[1]]
            elif operation == "write":
                matrix[location[0]][location[1]] = writedata
                return matrix
            else:
                raise OperationError("That is not a valid operation for this system.")
        except Exception as e:
            print(e)
            return -1
        
    • def matrix(matrice=list, operation=str, location=tuple, writedata=None):
    • if operation == "read":
    • try:
    • return matrice[location[0]][location[1]]
    • except Exception as e:
    • print(e)
    • return 0
    • elif operation == "write":
    • try:
    • matrice[location[0]][location[1]] = writedata
    • return matrice
    • except Exception as e:
    • print(e)
    • return 0
    • else:
    • raise OperationError("That is not a valid operation for this system.")
    • class OperationError(Exception):
    • def __init__(self, message):
    • super().__init__(message)
    • def matrix(matrix=list, operation=str, location=tuple, writedata=None):
    • try:
    • if operation == "read":
    • return matrix[location[0]][location[1]]
    • elif operation == "write":
    • matrix[location[0]][location[1]] = writedata
    • return matrix
    • else:
    • raise OperationError("That is not a valid operation for this system.")
    • except Exception as e:
    • print(e)
    • return -1
Code
Diff
  • function returnhundred() {
      return parseInt(('onehundred'.split('').map(x=>x.charCodeAt()).reduce((a,b)=>{ return (a > b) ? a - b : b - a}) / 4).toString(2))
    }
    • function returnhundred() {
    • return 'd'.charCodeAt();
    • return parseInt(('onehundred'.split('').map(x=>x.charCodeAt()).reduce((a,b)=>{ return (a > b) ? a - b : b - a}) / 4).toString(2))
    • }

removed list creations and limitation to pow(2, 12)

Code
Diff
  • def convert_decimalBinary(number):
        
        bin = ""
        
        while(number > 0):
            if number % 2 == 1:
                bin = "1" + bin
            else:
                bin = "0" + bin
            number = int(number/2)
        return int(bin)
    • def convert_decimalBinary(number: int) -> int:
    • """Convert number into binary without using bin()"""
    • powers = [pow(2, i) for i in range(12)][::-1]
    • binary = ['0' for i in range(len(powers))]
    • for i, num in enumerate(powers):
    • if num <= number:
    • number = number - num
    • binary[i] = '1'
    • return int(''.join(binary))
    • def convert_decimalBinary(number):
    • bin = ""
    • while(number > 0):
    • if number % 2 == 1:
    • bin = "1" + bin
    • else:
    • bin = "0" + bin
    • number = int(number/2)
    • return int(bin)