  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Finding numbers who digits ^ (digit position) == original number i.e. (89 = 8^1 + 9^2), but the code won't return anythi

## Finding numbers who digits ^ (digit position) == original number i.e. (89 = 8^1 + 9^2), but the code won't return anythi Tag : python , By : Adam Hill Date : December 05 2020, 12:18 PM

will be helpful for those in need I think, your code doesn't work, because the missing solution 1676 contains two times the 6. So str(i).index(x) will return the wrong index for the second 6 which makes the calculation faulty.
I guess, this is one of the times, where I'd start without list comprehensions and first get the code to work. Is this generally the result you want?
``````def sum_dig_pow(a, b):
result = []
for number in range(a, b+1):
calculation = 0
for position, digit in enumerate(map(int, str(number))):
calculation += digit**(position + 1)
if calculation == number:
result += [number]
return result

print(sum_dig_pow(1, 2000))
``````
``````[1, 2, 3, 4, 5, 6, 7, 8, 9, 89, 135, 175, 518, 598, 1306, 1676]
``````
``````def sum_dig_pow(a, b):
result = []
for number in range(a, b+1):
calculation = sum([digit**(position + 1) for position, digit in enumerate(map(int, str(number)))])
if calculation == number:
result += [number]
return result
``````
``````def sum_dig_pow(a, b):
return [number for number in range(a, b+1) if sum([digit**(position + 1) for position, digit in enumerate(map(int, str(number)))]) == number]
``````
``````sum_dig_pow = lambda a, b: [number for number in range(a, b+1) if sum([digit**(position + 1) for position, digit in enumerate(map(int, str(number)))]) == number]
`````` Boards Message : You Must Login Or Sign Up to Add Your Comments .

## Finding if two numbers have the same digit and then remove them from in the original number in Haskell

Tag : haskell , By : alchemist
Date : March 29 2020, 07:55 AM
Does that help Let x and y be the two numbers. Then one can remove the digits in x which it has in common with y like this:
``````Prelude> import Data.List
Prelude Data.List> let x = 68
Prelude Data.List> let y = 76
Prelude Data.List> read (show x \\ show y) :: Int
8
``````
``````s <- nub \$ intersect (show x) (show y)
``````
``````map (read . delete s . show) [x, y]
``````

## Code for finding the greatest product of five consecutive digits in the 1000-digit number

Tag : java , By : micaleel
Date : March 29 2020, 07:55 AM
will be helpful for those in need charAt() reports 48 for '0' and 49 for '1' etc. as it is the character values.
Subtract 48 from each and try again.

## how to get number of possible 4 digit numbers with constraints on possible digits and position of digits

Tag : math , By : user123585
Date : March 29 2020, 07:55 AM
this one helps. So our hint is: n1n2n3n4, use all of 1234 exactly once.
1) There are three places we can put 1 in, leaving us with _1n3n4, _n21n4 and _n2n31.
``````_1__
2143
4123
3142

__1_
3412
4312
2413

___1
4321
3421
2341
``````

## Find the a 4 digit number who's square is 8 digits AND last 4 digits are the original number

Tag : python , By : Alex S
Date : March 29 2020, 07:55 AM
I wish this helpful for you From the comments on my answer here, the question was asked (paraphrase): , Here is a 1-liner solution without any modules:
``````>>> next((x for x in range(1000, 10000) if str(x*x)[-4:] == str(x)), None)
9376
``````
``````>>> next((x for x in range(3163, 10000) if str(x*x)[-4:] == str(x)), None)
9376
``````

## Code for finding largest product of 13 consecutive digits of a 1000 digit number does not give required output

Tag : python , By : kiirpi
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The code is to find the largest possible product of 13 consecutive digits of a 1000 digit number. When I tried to run it on IDLE, it just gave RESTART and the directory where I saved the .py file. When I tried this on Pycharm(I know its not the IDE's problem, but I just had to try), no output. Am I doing something wrong? , Your original code can be simplified to the following.
``````

n=7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450

def product(j):
p = 1
for i in range(j,j+13):
p=p*s[i]
return(p)
s=[]
for i in range(0,1000):
s=s+[n%10]
n=n//10
k = 0
N = len(s)
j = 0
while j<N-13:  #need to 13 elements before end
c = product(j)
if c>k:
k=c
j = j + 1
print(k)
n=7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450

def product(j):
p = 1
for i in range(j,j+13):
p=p*s[i]
return(p)
s=[]
for i in range(0,1000):
s=s+[n%10]
n=n//10
k = 0
N = len(s)
j = 0
while j<N-13:  #need to 13 elements before end
c = product(j)
if c>k:
k=c
j = j + 1
print(k)

digits = str(n) # generates digits of number
products = [product(j) for j in range(1000-13)] # list comprehension
# uses you product function
print(max(products))
digits = str(n) # generates digits of number
products = [product(j) for j in range(1000-13)] # list comprehension
# uses you product function
print(max(products))
``````
``` ```
``` ```
``` ``` 