# Tag Info

### How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

This isn't the same solution as llhuii's, but it's also 42 bytes long. n=0;exec'print n;n^=(n^n+2)%3/2;n+=2;'*400 Try it online! Thanks to @JonathanFrech, we're ...
• 210k

### How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

Getting 39 bytes This is an explanation of how I got a 39-byte solution, which Dennis and JonathanFrech found separately as well. Or, rather, it explains how one could arrive at the answer in ...
• 145k

### Primality testing formula

43 bytes (4**n+1)**n%4**n**2/n&2**(2*n*n+n)/-~2**n<1 Try it online! The method is similar to Dennis' second (deleted) answer, but this answer is easier ...
• 17.3k

### Tips for restricted source in Python

Avoid "normal" letters Identifiers are normalized by the Python 3 parser. This implies that cursive (Unicode) letters such as πͺπ«π¬πππ are interpreted ...
• 105k
Accepted

### How to solve the LCM in 50 bytes of Python

My solution to 50 bytes: v=1 for x in input().split()*6**6:v+=-v%int(x) print(v) Explanation The solution itself is relatively simple, but finding it was ...
• 22.7k

### Tips for golfing in Python

Assignment expressions Assignment expressions are a powerful language feature introduced in Python 3.8 (TIO). Use the "walrus operator" := to assign a variable ...
• 145k

### Tips for golfing in Python

Common helper functions These are some golfed implementations of number theoretic functions that come up in challenges a lot. Many of these are due to xnor, especially the βWilsonβs theorem prime ...
• 68.8k

### Tips for golfing in Python

The shortest infinite for comprehension You may know the trick to easily create an infinite generator using the two-argument form of iter: ...
• 23.9k

### Tips for restricted source in Python

Avoid Numbers with Booleans When performing arithmetic operations on Booleans, Python treats them as if they are the numbers 1 and 0. So for example ...

### Tips for golfing in Python

Binomial coefficient The binomial coefficient $\binom{n}{k} \ = \frac{n!}{k!(n-k)!}$ can be expressed arithmetically as ((2**n+1)**n>>n*k)%2**n Try it ...
• 145k

### A game of dice, but avoid number 6

NeoBot Instead, only try to realize the truth - there is no spoon NeoBot peeks into the matrix (aka random) and predicts if the next roll will be a 6 or not - it can't do anything about being handed ...

### Tips for restricted source in Python

Avoid Parens with List indexing Parentheses are super useful for creating the correct operator precedence so it is a bummer when they are banned. However if [] are ...
Accepted

### FOIL Python's strong typing!

54 52 50 49 48 45 39 bytes Removed 4 bytes thanks to Dennis. The latest version is inspired by the "some reason" in xnor's answer. ...
• 37k

### Tips for restricted source in Python

Function calls without parentheses We can avoid using parentheses for operator precedence using list indexing, but parentheses are still very useful for calling functions. List indexing can be used ...
• 98.9k
Accepted

### How can I shorten this python code?

Instead of ((a*10+c)*10)+d we can use ((a*2+c)*2)+d to distinguish the colors. ...
• 68.8k

### Tips for restricted source in Python

Use << and | to generate constant without + Fun fact: You can get any positive ...
• 3,946

### Get the lowest possible pylint score within 128 bytes of python

-5430 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++exit("Hello World") Try it online!
• 271

### Robot Roulette: High stakes robot gambling

UpYours Being late to enter I spent a while admiring the existing bots, spent a while overcomplicating your guys' ideas, then un-overcomplicating them. Then it came to me Good artists copy, great ...
• 371
Accepted

### How to ignore first user input in Python 3

open(0), 40 bytes The builtin function open returns a file object which can be iterated over, line by line. Usually you pass a ...
• 59.7k

### Tips for golfing in Python

Split into chunks You can split a list into chunks of a given size using zip and iter, as explained in this SO question. ...
• 145k
Accepted

...
• 34.9k

### Tips for restricted source in Python

Access methods and built-in functions through __dict__ Classes contain a __dict__ attribute, which maps their method names to ...
• 1,596

### Robot Roulette: High stakes robot gambling

Kamikaze Why bother with complicated logic when we are all going to die anyway... def kamikaze(hp, history, ties, alive): return hp One shot It's going ...
• 323

### A game of dice, but avoid number 6

Cooperative Swarm Strategy I don't think anyone else has yet noticed the significance of this rule: If the game goes to 200 rounds, the bot (or bots) with the highest score is the winner, even if ...
• 151
Accepted

### Shortest Solution in Python 3 for Caught Speeding - CodingBat

Python 3, 32 bytes lambda a,b:(a-b*5>60)+(a-b*5>80) Try it online! Python 3, 50 49 bytes If io must be done with stdin and stdout ...
• 12.5k

### Tips for golfing in Python

If you want to know the type of a variable x: ...
• 22.2k

### How on earth did llhuii output the Evil Numbers in 42 bytes of Python?

This gives my (xnor's) 47-byte solution and the thinking that led me to it. Don't read this if you want to figure this out yourself. A natural first idea is to iterate through the numbers 0 to 799, ...
• 145k

### Robot Roulette: High stakes robot gambling

Pathetic Bot gets a much needed upgrade: The pathetic attempt at a bot that tries to incorporate other bots' features ...
• 141