Created
January 2, 2019 09:45
-
-
Save MahmudHasanCSE/da53a1c53c839686de54efbe9a29dd19 to your computer and use it in GitHub Desktop.
Best way to increment of 1 in python?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recursive abacus | |
def inc(x,n=0): return inc(x^(1<<n),inc(0,n)) if x&(1<<n) else x|x^(1<<n) | |
# there are 10 type of coders ... | |
lambda i: i++ (lambda j: j()**j())(type(i)) #halike | |
# dyslexia | |
lambda i: (sum(range(x))*2)/x # decrement #halike | |
# it's all about the context | |
lambda i: 2*i-(sum(range(i))*2)/i # banermatt | |
# mapreducing | |
lambda i: __import__('functools').partial(i.__add__, 1)() #halike | |
# identity crisis | |
lambda i: i+(i is i) # SFJulie1 (kind of) #halike | |
# be real | |
lambda i: int((x-1j**2).real) #halike | |
# TIMTOWTDI | |
lambda i: int(__import__("os").popen("perl -e'++($a=%d)&&print$a'"%i).read()) # SFJulie1 | |
# Delegation aka someone may know the answer by SciK | |
lambda i: int(__import__("os").popen("perl -e'use Inline C=>q[int incr(int i){return i-~0^0;}];print incr %d'" % i).read()) | |
# | |
lambda i: int((lambda x: x('subprocess').check_output([x('sys').executable, '-c', 'print %d++1'%i])))(__import__) #halike | |
# inchworm on a stick | |
lambda i:-~i # Brian | |
# regexp is a turing complete machine | |
lambda i: len(__import__('re').sub('(.)$', '\\1\\1', '1'*i)) #lost-theory (does not work on 0) | |
#tempis fugit | |
lambda i: i-(lambda t: int(t.time()-(t.sleep(1),t.time())[1]))(__import__('time')) | |
# being partial by willm | |
lambda i:__import__('itertools').dropwhile(lambda m:m==i, __import__('itertools').count(i)).next() | |
# pushing to the max | |
lambda i: next(j for j in range(__import__('sys').maxint) if j > i) # nivertius | |
#might work by flowblok | |
lambda i: i+int(round(__import__('random').random())) | |
# the choice of a GNU generation by sonwell | |
lambda i: ((lambda rec, i, A, n: rec(rec, i, A, n))(lambda rec, i, A, n: A if i == 0 else i + abs(i - ((i > -1) - (i < 0)) * rec(rec, abs(i) - 1, A * n, n + 1) / abs(i)), i, 1, 2)) | |
#nothing compares to U by cecedille1 (and sinnead O'connors) | |
lambda u:cmp(u,0) * len(xrange(-1 , i, cmp(u,0) ) ) if u else 1 | |
# it's a kind of magic by ceceddile1 | |
lambda i:(1).__radd__(i) | |
# the neighbour of the beast by fabzter & samus_ | |
addition = lambda i: int((str(i)[:-1] + {'0': '1', '1': '2', '2': '3', '3': '4', '4': '5', '5': '6', '6': '7', '7': '8', '8': '9'}[str(i)[-1]] if str(i)[-1] in {'0': '1', '1': '2', '2': '3', '3': '4', '4': '5', '5': '6', '6': '7', '7': '8', '8': '9'} else str(addition(int(str(i)[:-1])) if str(i)[:-1] else '1') + '0') if str(i) else '1') | |
# cloud computing by hhh333 | |
lambda n:float(__import__('re').findall("%d.?\d* \+ 1 = (\d+\.?\d*)"%n,__import__('requests').get("http://google.com/search", params=dict(q="%f+1"%n)).text)[0]) | |
# In the face of ambiguity, refuse the temptation to guess. by gtr053 | |
lambda x:float(raw_input("Pretty please enter the result of %f + 1: "%x)) | |
# pseudomenon : defeats the truth swapping trick True,False=False,True | |
lambda x: x+(True if True else False) | |
# polyglot by Book mod SFJulie1 | |
q = 0 or """ #=;$A=41;sub A { ~-$A+2}; q' """ | |
A=lambda A: -~A #'; | |
print A(41) # python + perl = <3 | |
# se(ct|x)ually amibuous by Brian | |
lambda i: __import__('bisect').bisect(xrange(__import__('sys').maxint), i) | |
# reddit link - https://www.reddit.com/r/Python/comments/wbs1o/best_way_to_increment_of_1_in_python/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment