New answers tagged python
1
Checking if a boolean value is false and an integer is a specific odd integer
~True is ~1 is -2 and ~False is ~0 is -1
-1&int is always int
-2&int is always even
Therefore, despite operator order, ~bool&int==odd_int works fine.
It's shorter than all of these equivalents:
not bool and int==odd_int
-~bool and int==odd_int
-~bool&int==odd_int
7
21 bytes, solves Shortest code to throw SIGILL
“A{gœỴ¹⁻ėe⁾÷ỤḞḂ4ḷ$»ŒV
Try it online!
This decompresses to the following Python 3 code (which is 22 bytes long, only one byte longer than the compressed version):
import os
os.kill(0,4)
Try it online!
The basic idea is to pick a task that's completely out of scope for Jelly; in this case, we're interacting with ...
5
Jelly, 21 bytes, cracks Jonathan Allan's answer
“¡ẉḟUHġ[4A»ŒVw⁾SuNXṛ⁸
Try it online!
Takes the return value of time.ctime(), finds Su in it, and negates the value. On a Sunday, this passes -1 to X (random number function), causing an error. Otherwise it passes 0 to X, not erroring. then final return value is forced to be the empty string ⁸, so it will print ...
7
25 bytes, solves We had a question once which only failed on Sundays - Cracked (Razetime)
“ÇṄṚ,Ḣ¢;Xv^wME ṖƘżẓ⁸9!»ŒV
Try it online!
The compressed code is heavily based on Mr XCoder's submission:
exit('Su'in time.ctime()<_)
Notes:
There's no need to import time since Jelly's interpreter does that, but not much is exposed, just sleeping and simple time ...
4
132 bytes, solves this - Non-competing
“ßẏƊḢ⁵'ĠȦṫ-ỵḲ²ƘçẠaðṁ¹ĠẊḊƝ;ɠ)ṭKpƭȯVsRDỤ⁵ṾḶĿṇƈ>bỴøỴ⁻Ñy1®ḶṪ\ḷ⁶ḋẇƊ⁾L⁼ṀHṃYṘZ1ẏ1ʋḤFTʠzɱĊȦṁƈṠ!ỌẎḌʂ&B?o#Ṗ³⁻Eḋ4ỤṙṃɲɼĖṬƘmẏġ^wp=ạİQƊ)Ḅı/ẉNẊ`»ŒV
I don't really know Python, so I used Javascript, executed by Python, executed by Jelly. Try it online!
The Python code:
import os
os.system("node -e \"console.log((x=>...
2
Guesser: BayesBot
import random
from typing import Callable
def Main(rng: random.Random, liar: Callable[[int], int]):
num_possibilities = 256
max_lies = 8
distribution = {(secret, max_lies) : 1. / num_possibilities for secret in range(num_possibilities)}
lie_rates = [
0, 0.211, 0.195,
0.188, 0.138, 0.207,
0.202, 0....
1
Liar: Illusionist
import random
class Main:
def __init__(self, rng: random.Random, secret: int):
self.rng = rng
self.secret = secret
self.fake_secret = (127-secret)%256
self.unreserved_lies = 4
self.prev_lies = []
def __call__(self, guess: int) -> int:
if guess < self.secret:
...
5
Guesser: phoenix_wright
import random
from typing import Callable
def Main(rng: random.Random, liar: Callable[[int], int]):
while liar(0) == -1: pass
previous = {0:1}
lb = 0
ub = 255
while True:
while lb <= ub:
g = (lb+ub)//2
if g in previous:
r = previous[g]
else:
...
2
Liar: keep_away
"""A liar that tries to keep the guesser away from the secret"""
import random
class Main:
def __init__(self, rng: random.Random, secret: int):
"""Store the rng and secret."""
self.rng = rng
self.secret = secret
self.lb = 0
self.ub = 255
...
1
Liar: one_big_lie
"""A liar that lies once at the very beginning"""
import random
class Main:
def __init__(self, rng: random.Random, secret: int):
"""Store the rng and secret."""
self.rng = rng
self.secret = secret
self.lied = False
def __call__(self,guess):
...
Top 50 recent answers are included
Related Tags
python × 114code-golf × 69
tips × 45
king-of-the-hill × 19
game × 7
code-challenge × 5
optimization × 5
popularity-contest × 4
primes × 4
programming-puzzle × 4
string × 3
math × 3
restricted-source × 3
fastest-code × 3
board-game × 3
kolmogorov-complexity × 2
array-manipulation × 2
decision-problem × 2
geometry × 2
cops-and-robbers × 2
palindrome × 2
card-games × 2
test-battery × 2
error-message × 2
jelly × 2