7
The Challenge
Given an integer, calculate its score as described below.
The score is calculated by raising each digit of the input Integer to the power n
, where n
denotes the index of the digit in Input (beginning with 1) when counted from left to right (the index of leftmost digit should be 1), and then summing them all together. If the original number happens to be prime, then add the largest digit of the input integer to the score, else subtract the smallest digit of the input integer from it.
Input
Your program should take an integer as input. You can take the input in whatever way you want to.
Output
Output the score of the input integer through whatever medium your programming language supports. Function return
is also allowed.
Test Cases
5328 -> (5^1)+(3^2)+(2^3)+(8^4)-2 = 4116
3067 -> (3^1)+(0^2)+(6^3)+(7^4)+7 = 2627
7 -> (7^1)+7 = 14
Scoring
This is code-golf, so the shortest code in bytes wins!
Hello and welcome to the site! In order for questions to be considered on-topic here it needs an "objective winning criterion" that means that there needs to be some goal everyone is attempting to attain with there answers. The most common one is [tag:code-golf] which means answers should aim to minimize their source length. – Post Rock Garf Hunter – 2017-03-24T02:44:47.967
3Aside from being off topic because there is no winning criterion (a formality, as tagging it with, e.g., code-golf would solve that), there are a few issues. 1. Where do we get
5^1 + 3^2 + 2^3 + 8^4
from? That doesn't seem to be explained anywhere. 2. Strings are forbidden, but what about arrays? 3. If we write a program, how are we supposed to take input if we're not allowed to use strings? – Dennis – 2017-03-24T02:46:47.8933
There is a Sandbox where you can post challenge ideas and get feedback from the community without it affecting your site reputation. It's generally a good idea to leave it in there for at least a week
– MildlyMilquetoast – 2017-03-24T02:56:09.557To be clear, you mean the largest/smallest digit numerically, not the rightmost/leftmost digit, right? – Greg Martin – 2017-03-28T17:06:20.940
This challenge was made code golf so it could be reopened. That means the shortest answer should be accepted. – Dennis – 2017-03-29T17:07:03.313