We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I used more math than programming in this question.
defformposicaodig(x):'''Howmanydigitsarethereuptothefirstdigitofx(x-10^(n-1))*n+[sum9*(10^(k-2))*(k-1),fromk=2ton]=(x-10**(n-1))*n+n*10**(n-1)+(1-10**n)//9'''n=len(str(x))return1+(x-10**(n-1))*n+n*10**(n-1)+(1-10**n)//9defformInvposicaodig(pos):'''x=Thepositiondigit'pos'iscontainedinwhichnumbern=len(str(x)):Numberofdigitsinxx=(pos+(10**n-1)//9 - n * 10**(n-1) -1) / n + 10**(n-1) return:WhatisthenthdigitofChampernowne'sconstant'''n=len(str(pos))xcalc=(pos+(10**n-1)//9 - 1) // n# As I don't know the number of digits of x, # I iterate until the xcal found is equal to the size of the formula to determine it.whilen!=len(str(xcalc)):n=len(str(xcalc))xcalc=(pos+(10**n-1)//9 - 1) // nreturnint(str(xcalc)[pos-formposicaodig(xcalc)])n=int(input())forkinrange(n):prd=1forjinmap(int,input().split()):nth=formInvposicaodig(j)ifnth==0:prd=0breakelse:prd*=nthprint(prd)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #40: Champernowne's constant
You are viewing a single comment's thread. Return to all comments →
I used more math than programming in this question.