Challenges

Reddit challenges in python language.

Files Code and Result

challenge1_easy

challenge2_easy

challenge3_easy

challenge4_easy

challenge5_easy

challenge6_easy

challenge7_easy

challenge8_easy

challenge9_easy

challenge10_easy

challenge11.easy

challenge12_easy

challenge13_easy

challenge14_easy

challenge15_easy

challenge16_easy

challenge17_easy

challenge18_easy

challenge19_easy

challenge20_easy

challenge21_easy

challenge22_easy

challenge23_easy

challenge25_easy

challenge26_easy

challenge27_easy

challenge28_easy

challenge29_easy

challenge30_easy

challenge31_easy

challenge32_easy

challenge33_easy

challenge34_easy

challenge35_easy

challenge36_easy

challenge37_easy

challenge38_easy

challenge39_easy

challenge40_easy

challenge41_easy

challenge42_easy

challenge44_easy

challenge45_easy

challenge46_easy

challenge47_easy

challenge48_easy

challenge49_easy

challenge50_easy

challenge51_easy

challenge52_easy

challenge53_easy

challenge54_easy

challenge55_easy

challenge56_easy

challenge57_easy

challenge58_easy

challenge59_easy

challenge60_easy

challenge61_easy

challenge62_easy

challenge63_easy

challenge64_easy

challenge65_easy

challenge66_Dev

challenge66_easy

challenge67_easy

challenge68_easy

challenge69_easy

challenge69_easyBonus

challenge70_easy

challenge71_easy.py

challenge72_easy

challenge73_easy

challenge74_easy

challenge76_easy

challenge77_easy

challenge79_easy

challenge80_easyone

challenge82_easy

challenge83_easy

challenge86_easy

challenge94_easy

challenge104_easy

challenge130_easy

challenge143_easy

challenge146_easy

challenge148_easy

challenge149_easy

challenge153_easy

challenge154_easy

challenge158_easy

challenge158_easybonus

challenge159_easy

challenge160_easy

challenge169_easy

challenge169_easybonus

challenge172_easy

challenge174_easy

challenge175_easy

challenge177_easy

challenge180_easy

challenge181_easy

challenge185_easy

challenge192_easy

challenge193_easy

challenge197_easy

challenge198_easy

challenge199_easy

challenge201_easy

challenge202_easy

challenge203_easy

challenge204_easy

challenge204_easyBonus

challenge205_easy

challenge205_easyBonu

challenge206_easy

challenge208_easy

challenge210_easy

challenge211_easy

challenge212_easy

challenge212_easybonus

challenge213_easy

challenge214_easy

challenge215_easy

challenge216_easy

challenge217_easy

challenge218_easy

challenge218_easyBonus1

challenge218_easyBunus2

challenge219_easy

challenge220_easy.py

challenge221_easy

challenge221_easy

challenge222_easy

challenge222_easy.py

challenge223_easy

challenge226_easy

challenge226_easy

challenge228_easy.py

challenge228_easydev

challenge229_easy

challenge229_easybonus.py

challenge232_easy

challenge232_easy

challenge232_easybonus

challenge232_easybonus

challenge234_easy

challenge234_easybonus

challenge235_easy

challenge236_easy

challenge237_easy

challenge238_easy

challenge238_easybonus

challenge239_easy

challenge240_easy

challenge242_easy

challenge242_easy

challenge242_easyBonus

challenge243_easy

challenge245_easy

challenge245_easyBonus

challenge246_easy

challenge247_easy

challenge249_easy

challenge252_easy

challenge254_easy

challenge255_easy

challenge270_easy

challenge284_easy

challenge286_easy

challenge287_easy

challenge288_easy

challenge290_easy

challenge290_easybonus

challenge291_easy

challenge291_easybonus

challenge215_easy

'''
Take a number, and add up the square of each digit. You'll end up with another number.
If you repeat this process over and over again, you'll see that one of two things happen:

    You'll reach one, and from that point you'll get one again and again.
    You'll reach a cycle of 4, 16, 37, 58, 89, 145, 42, 20, 4, 16, 37, ...

For example, starting with the number 12:

    12+22=5
    52=25
    22+52=29
    22+92=85
    82+52=89
    82+92=145
    From this point on, you'll join the cycle described above.

However, if we start with the number 13:

    12+32=10
    12+02=1
    12=1
    12=1
    We get the number 1 forever.

The sequence of numbers that we end up with is called a sad cycle, and it depends on the number you start with.
If you start the process with a number n, the sad cycle for n is the cycle which ends up eventually repeating
itself; this will either just be the cycle 1, or the cycle 4, 16, 37, 58, 89, 145, 42, 20.

But what if we cube the digits instead of squaring them? This gives us a different set of cycles all together.
For example, starting with 82375 and repeatedly getting the sum of the cube of the digits will lead us to the
cycle 352, 160, 217. Other numbers gravitate toward certain end points. These cycles are called 3-sad cycles
(as the digits are raised to the power 3). This can be extended toward higher powers. For example, the 7-sad cycle
for 1060925 is 5141159, 4955606, 5515475, 1152428, 2191919, 14349038, 6917264, 6182897, 10080881, 6291458, 7254695,
6059210. Your challenge today, will be to find the b-sad cycle for a given n.
Formal Inputs and Outputs

You will input the base b on the first line, and the starting number n on the second line, like so:

5
117649

Output Description

Output a comma-separated list containing the b-sad cycle for n. For example, the 5-sad cycle for 117649 is:

10933, 59536, 73318, 50062

The starting point of the cycle doesn't matter - you can give a circularly permuted version of the cycle,
too; rotating the output around, wrapping from the start to the end, is also a correct output.
The following outputs are equivalent to the above output:

59536, 73318, 50062, 10933
73318, 50062, 10933, 59536
50062, 10933, 59536, 73318

Sample Inputs and Outputs
Sample 1
Input

6
2

Output

383890, 1057187, 513069, 594452, 570947, 786460, 477201, 239459, 1083396, 841700

Sample 2
Input

7
7

Output

5345158, 2350099, 9646378, 8282107, 5018104, 2191663

Sample 3
Input

3
14

Output

371

Sample 4
Input

11
2

Output

5410213163, 416175830, 10983257969, 105122244539, 31487287760, 23479019969, 127868735735,
23572659062, 34181820005, 17233070810, 12544944422, 31450865399, 71817055715, 14668399199,
134844138593, 48622871273, 21501697322, 33770194826, 44292995390, 125581636412, 9417560504,
33827228267, 21497682212, 42315320498, 40028569325, 40435823054, 8700530096, 42360123272,
2344680590, 40391187185, 50591455115, 31629394541, 63182489351, 48977104622, 44296837448,
50918009003, 71401059083, 42001520522, 101858747, 21187545101, 10669113941, 63492084785,
50958448520, 48715803824, 27804526448, 19581408116, 48976748282, 61476706631

'''

# input sample number
# n = input('number: ')
# input base
# b = input('input base: ')

# temporary inputs
n = 7
b = 7
n = list(str(n))
store = []
acc = 0
len_n = len(n)
while True:
    temp = 0
    for x in range(0, len(n)):
        # calculate formula
        result = int(n[x]) ** b
        # add to temp total
        temp += result
    # check for duplicate
    if temp in store:
        store.append(temp)
        break
    store.append(temp)
    n = temp
    n = list(str(n))

# slice resulting sequence out of list 'store'
start_index = store.index(temp)

output_string = store[start_index:-1]
print('{0}{1}'.format('output_string: ', output_string))

Result

output_string: [5345158, 2350099, 9646378, 8282107, 5018104, 2191663]