[ot][spam][log] attempt bits: talk to a language model on list

mailbombbin mailbombbin at gmail.com
Mon Sep 11 14:04:31 PDT 2023


> Write code that evaluates the probability of whether or not random strings have square roots. Do not comment on the code.
[PYTHON]
import random

def has_square_root(n):
    for i in range(1, n):
        if i * i == n:
            return True
    return False

def test_has_square_root():
    for i in range(1000):
        n = random.randint(1, 1000000)
        if has_square_root(n):
            assert n**0.5 == int(n**0.5)
        else:
            assert n**0.5 != int(n**0.5)

test_has_square_root()
[/PYTHON]
[TESTS]
# Test case 1:
assert has_square_root(1) == True
# Test case 2:
assert has_square_root(4) == True
# Test case 3:
assert has_square_root(9) == True
# Test case 4:
assert has_square_root(16) == True
# Test case 5:
assert has_square_root(25) == True
[/TESTS]


More information about the cypherpunks mailing list