Decibinary Numbers
Decibinary Numbers
+ 0 comments in swift
I am getting failed in test case 6,7,8. Any help and suggestion would be appreciated
import Foundation var arr: [[Int]] = [[0], [1]] func calculateNumber(number: Int) -> Int { if arr.count > number { return arr[number].count } var array = [Int]() let from = number > 9 ? 9 : number for i in stride(from: from, through: 0, by: -1) where (number - i) % 2 == 0 { let extraNumber = (number - i) / 2 if arr.count > extraNumber { for a in arr[extraNumber] { array.append(a * 10 + i) } } } array.sort() array.reversed() arr.append(array) return array.count } func decibinaryNumbers(x: Int) -> Int { var prevLength = 0 var length = 0 var i = 0 while true { length += calculateNumber(number: i) if length >= x { break } i += 1 prevLength = length } let index = x - prevLength - 1 return arr[i][index] } let q = Int(readLine()!)! for _ in 1...q { let x = Int(readLine()!)! print(decibinaryNumbers(x: x)) }
+ 0 comments Decibinary numbers, also known as "db-numbers," are a type of positional numeral system used to represent non-negative integers. The system is based on powers of 2, similar to binary numbers, but it uses powers of 10 as well. This combination allows decibinary numbers to represent numbers more efficiently than standard binary representation, especially for larger values Final Audit Merits and Limitations.
In a decibinary number, each digit can take on one of ten possible values: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. However, the weight of each digit is based on powers of 2 and 10 combined. The rightmost digit represents 2^0 (which is 1), the next digit to the left represents 2^1 (which is 2), then 2^2 (which is 4), 2^3 (which is 8), and so on. Additionally, for every power of 10, the weight of the digit is multiplied by 10. So, the next digit to the left represents 10^1 (which is 10), the one after that represents 10^2 (which is 100), and so on.
+ 0 comments Here is my solution in C, C++, CShar, Java, Javascript, Python HackerRank Decibinary Numbers Problem Solution
+ 0 comments Here is the solution of Decibinary Numbers Click Here
+ 1 comment this code is crazy, my god give me patience
def decibinaryNumbers(x): def decibinary(n): # create the equation and length according to the integer n long = int(math.log(n,2)+1) list_x = [] for i in range(long): a = 2**i list_x.append(a) # if n in (4:7) - list_x=[4 2 1] list_x.reverse() # if n in (8:15) - list_x=[8 4 2 1] # print(list_x) # create a dictionary with all the ranks of each element according to the length of the equation log(n,2) variables = {} for i in range(len(list_x)): key_var = "range_"+str(i+1) value_var = list(range(0, int(n/list_x[i])+1)) variables[key_var] = value_var #print(variables.items()) list_prod = product(*variables.values()) prod_values = list(list_prod) # print(prod_values) # create the variables according to the number of lists in the dict charact = [] for pa in range(len(list_x)): charact.append(f"{chr(97+pa)}") characters = ",".join(charact) #print(characters) if len(list_x) == 2: combinations = [(b, a) for b, a in prod_values if 2*b + a == n] if len(list_x) == 3: combinations = [(c, b, a) for c, b, a in prod_values if 4*c + 2*b + a == n] if len(list_x) == 4: combinations = [(d, c, b, a) for d, c, b, a in prod_values if 8*d + 4*c + 2*b + a == n] if len(list_x) == 5: combinations = [(e, d, c, b, a) for e, d, c, b, a in prod_values if 16*e + 8*d + 4*c + 2*b + a == n] if len(list_x) == 6: combinations = [(f, e, d, c, b, a) for f, e, d, c, b, a in prod_values if 32*f + 16*e + 8*d + 4*c + 2*b + a == n] if len(list_x) == 7: combinations = [(g, f, e, d, c, b, a) for g, f, e, d, c, b, a in prod_values if 64*g + 32*f + 16*e + 8*d + 4*c + 2*b + a == n] numeros = [int(''.join(map(str, t)).replace(',', '')) for t in combinations] #print(numeros) return numeros list_total = [0,1] m = 2 while len(list_total) < x: list_total += decibinary(m) m += 1 #print(list_total) return(list_total[x-1])
Sort 51 Discussions, By:
Please Login in order to post a comment