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

challenge78_easy

challenge79_easy

challenge80_easyone

challenge82_easy

challenge83_easy

challenge84_easy

challenge85_easy

challenge85_easybonus

challenge86_easy

challenge87_easy

challenge88_easy

challenge88_easybonus

challenge89_easy

challenge90_easy

challenge91_easy

challenge92_easy

challenge93_easy

challenge94_easy

challenge95_easy

challenge96_easy

challenge97_easy

challenge98_easy

challenge99_easy

challenge100_easy

challenge100_easybonus

challenge101_easy

challenge101_easybonus

challenge102_easy

challenge103_easy

challenge104_easy

challenge105_easy

challenge106_easy

challenge107_easy

challenge108_easy

challenge109_easy

challenge110_easy

challenge111_easy2

challenge112_easy

challenge113_easy

challenge114_easy

challenge115_easy

challenge116_easy

challenge117_easy

challenge118_easy

challenge119_easy

challenge121_easy

challenge122_easy

challenge123_easy

challenge124_easy

challenge125_easy

challenge126_easy

challenge127_easy

challenge128_easy

challenge130_easy

challenge131_east

challenge132_easy

challenge133_easy

challenge134_easy

challenge135_easy

challenge136_easy

challenge137_easy

challenge138_easy

challenge139_easy

challenge140_easy

challenge141_easy

challenge142_easy

challenge143_easy

challenge144_easy

challenge145_easy

challenge146_easy

challenge147_easy

challenge148_easy

challenge149_easy

challenge153_easy

challenge153_easy

challenge154_easy

challenge156_easy

challenge157_easy

challenge158_easy

challenge158_easybonus

challenge159_easy

challenge160_easy

challenge161_easy

challenge162_easy

challenge163__easy

challenge168_easy

challenge169_easy

challenge169_easybonus

challenge170_easy

challenge171_easy

challenge172_easy

challenge174_easy

challenge175_easy

challenge177_easy

challenge179_easy

challenge180_easy

challenge181_easy

challenge182_easy

challenge184_easy

challenge185_easy

challenge188_easy

challenge189_easy_ascii

challenge191_easy

challenge192_easy

challenge193_easy

challenge195_easy

challenge197_easy

challenge198_easy

challenge199_easy

challenge200_easy

challenge201_easy

challenge202_easy

challenge203_easy

challenge204_easy

challenge204_easyBonus

challenge205_easy

challenge205_easyBonu

challenge206_easy

challenge207_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

challenge231_easy

challenge232_easy

challenge232_easy

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

challenge251_easy

challenge251_easy

challenge251_easybonus

challenge252_easy

challenge252_easy

challenge253_easy

challenge254_easy

challenge255_easy

challenge257_easy

challenge261_easy

challenge267_easy

challenge269_easy

challenge270_easy

challenge272_easy

challenge277_easy

challenge282_easy

challenge282_easy_bonus

challenge283_easy

challenge284_easy

challenge286_easy

challenge287_easy

challenge288_easy

challenge290_easy

challenge290_easybonus

challenge291_easy

challenge291_easybonus

challenge302_easy

challenge308_easy

challenge311_easy

challenge313_easy

challenge313_easy

challenge314_easy

challenge315_easy

challenge319_easy

challenge323_easy

challenge324_easy

challenge325_easy

challenge328_easy

challenge330_easy

challenge330_easybonus

challenge335_easy

challenge338_easy

challenge340_easy

challenge341_easy

challenge342_easy

challenge344_easy

challenge313_easy

'''
Given a sorted list of distinct integers, write a function that returns whether
there are two integers in the list that add up to 0. For example, you would
return true if both -14435 and 14435 are in the list, because -14435 + 14435 = 0.
Also return true if 0 appears in the list.
Examples

[1, 2, 3] -> false
[-5, -3, -1, 2, 4, 6] -> false
[] -> false
[-1, 1] -> true
[-97364, -71561, -69336, 19675, 71561, 97863] -> true
[-53974, -39140, -36561, -23935, -15680, 0] -> true

Optional Bonus Challenge

Today's basic challenge is a simplified version of the subset sum problem.
The bonus is to solve the full subset sum problem. Given a sorted list of
distinct integers, write a function that returns whether there is any
non-empty subset of the integers in the list that adds up to 0.

Examples of subsets that add up to 0 include:

[0]
[-3, 1, 2]
[-98634, -86888, -48841, -40483, 2612, 9225, 17848, 71967, 84319, 88875]

So if any of these appeared within your input, you would return true.

If you decide to attempt this optional challenge, please be aware that the
subset sum problem is NP-complete. This means that's it's extremely unlikely
that you'll be able to write a solution that works efficiently for large inputs.
If it works for small inputs (20 items or so) that's certainly good enough.
Bonus Challenge Examples

The following inputs should return false:

[-83314, -82838, -80120, -63468, -62478, -59378, -56958, -50061, -34791,
-32264, -21928, -14988, 23767, 24417, 26403, 26511, 36399, 78055]
[-92953, -91613, -89733, -50673, -16067, -9172, 8852, 30883, 46690, 46968,
56772, 58703, 59150, 78476, 84413, 90106, 94777, 95148]
[-94624, -86776, -85833, -80822, -71902, -54562, -38638, -26483, -20207,
-1290, 12414, 12627, 19509, 30894, 32505, 46825, 50321, 69294]
[-83964, -81834, -78386, -70497, -69357, -61867, -49127, -47916, -38361,
-35772, -29803, -15343, 6918, 19662, 44614, 66049, 93789, 95405]
[-68808, -58968, -45958, -36013, -32810, -28726, -13488, 3986, 26342, 29245,
30686, 47966, 58352, 68610, 74533, 77939, 80520, 87195]

The following inputs should return true:

[-97162, -95761, -94672, -87254, -57207, -22163, -20207, -1753, 11646, 13652,
14572, 30580, 52502, 64282, 74896, 83730, 89889, 92200]
[-93976, -93807, -64604, -59939, -44394, -36454, -34635, -16483, 267, 3245,
8031, 10622, 44815, 46829, 61689, 65756, 69220, 70121]
[-92474, -61685, -55348, -42019, -35902, -7815, -5579, 4490, 14778, 19399,
34202, 46624, 55800, 57719, 60260, 71511, 75665, 82754]
[-85029, -84549, -82646, -80493, -73373, -57478, -56711, -42456, -38923,
-29277, -3685, -3164, 26863, 29890, 37187, 46607, 69300, 84808]
[-87565, -71009, -49312, -47554, -27197, 905, 2839, 8657, 14622, 32217, 3556
'''
def subset(l):
    lst_sum = 0
    l = re.findall('[-]\d+|\d+', l)
    l = list(map(int, l))
    for num in l:
        num_pos = num * -1
        if 0 or num_pos in l:
            return True
    return False

def zubset(l):
    l = re.findall('[-]\d+|\d+', l)
    l = list(map(int, l))
    for x in range(2, len(l)):
        test = list(itertools.combinations(l, x))
        for tup in test:
            num = sum(tup)
            if num == 0:
                return True
    return False


import itertools

lsts = '''[0]
[-3, 1, 2]
[-98634, -86888, -48841, -40483, 2612, 9225, 17848, 71967, 84319, 88875]'''

lists = '''[-83314, -82838, -80120, -63468, -62478, -59378, -56958, -50061, -34791, -32264, -21928, -14988, 23767, 24417, 26403, 26511, 36399, 78055]
[-92953, -91613, -89733, -50673, -16067, -9172, 8852, 30883, 46690, 46968, 56772, 58703, 59150, 78476, 84413, 90106, 94777, 95148]
[-94624, -86776, -85833, -80822, -71902, -54562, -38638, -26483, -20207, -1290, 12414, 12627, 19509, 30894, 32505, 46825, 50321, 69294]
[-83964, -81834, -78386, -70497, -69357, -61867, -49127, -47916, -38361, -35772, -29803, -15343, 6918, 19662, 44614, 66049, 93789, 95405]
[-68808, -58968, -45958, -36013, -32810, -28726, -13488, 3986, 26342, 29245, 30686, 47966, 58352, 68610, 74533, 77939, 80520, 87195]
[-97162, -95761, -94672, -87254, -57207, -22163, -20207, -1753, 11646, 13652, 14572, 30580, 52502, 64282, 74896, 83730, 89889, 92200]
[-93976, -93807, -64604, -59939, -44394, -36454, -34635, -16483, 267, 3245, 8031, 10622, 44815, 46829, 61689, 65756, 69220, 70121]
[-92474, -61685, -55348, -42019, -35902, -7815, -5579, 4490, 14778, 19399, 34202, 46624, 55800, 57719, 60260, 71511, 75665, 82754]
[-85029, -84549, -82646, -80493, -73373, -57478, -56711, -42456, -38923, -29277, -3685, -3164, 26863, 29890, 37187, 46607, 69300, 84808]
[-87565, -71009, -49312, -47554, -27197, 905, 2839, 8657, 14622, 32217, 35567, 38470, 46885, 59236, 64704, 82944, 86902, 90487]'''

import re

lsts = lsts.splitlines()

for lst in lsts:
    truth = subset(lst)
    print(truth)
print('-------------------------')
lists = lists.splitlines()

for lst in lists:
    truth = zubset(lst)
    print(truth)

Result

True
False
False
-------------------------
False
False
False
False
False
True
True
True
True
True