Challenge: Implement incrementation without addition, multiplication, exponentiation, and any higher binary operators (and their opposites) in Python. Winner is the person who can do it in the least amount of code. You score 5 characters less if you can do it for negative numbers and without unary operators.
3
Just good ol' unary Demo
|
|||
Did this answer by arshajii help you? It's easy to give back. Sign up to get started. | |||
|
14I'm not a python guy, so here we go:
According to the docs, I don't use addition, only string concatenation and repetition. |
|||||||||
|
17 charactersNot shortest, but another way. This time no maths or binary operators involved at all. But it only works on numbers greater than -1.
Proof:
28 = 33-5 charactersDefinitely out of contention but this does it for all positive and negative integers, again no math, no unary tricks.
Proof:
|
||||
|
10 - 5 = 5
Demo
|
|||||||||||||||||||||
|
27-5=22 It's not really very short, but it doesn't use len(), range(), sum() and other stuff which definitely has a lot of increments and additions in it. Works with negative numbers, and no unary operations. Only pure, natural, raw, organic bitwise magic :)
Demo:
(UPD: Sorry, I'm not sure whether newlines are counted as chars, if yes, it should be 29 not 27...) |
|||
|