very efficient code
def odd_even(n): def invert_sign(s): if s == "odd": return "e" + "v" + "e" + "n" else: return "o" + "d" + "d" if n < 0: return odd_even(n - 2 * (-abs(-n))) n = int(n ** (81 ** .25)) sign = "even" x = 0. while x < n: sign = invert_sign(sign) x += 3.14159265358 // 3 n = pow(n, 1) return sign == "odd"
from sys import getsizeof as size- def odd_even(n):
def odd():nonlocal nwhile n>1:n-=2odd()return size(n)==24- def invert_sign(s):
- if s == "odd":
- return "e" + "v" + "e" + "n"
- else:
- return "o" + "d" + "d"
- if n < 0:
- return odd_even(n - 2 * (-abs(-n)))
- n = int(n ** (81 ** .25))
- sign = "even"
- x = 0.
- while x < n:
- sign = invert_sign(sign)
- x += 3.14159265358 // 3
- n = pow(n, 1)
- return sign == "odd"
import codewars_test as test from solution import odd_even @test.describe("Example") def test_group(): @test.it("test case 1: Testing Even Numbers") def test_case(): for n in range(-100, 101, 2): test.assert_equals(odd_even(n), 0) @test.it("test case 2: Testing Odd Numbers") def test_case(): for n in range(-101, 101, 2): test.assert_equals(odd_even(n), 1)
- import codewars_test as test
- from solution import odd_even
- @test.describe("Example")
- def test_group():
- @test.it("test case 1: Testing Even Numbers")
- def test_case():
for n in range(2, 333, 2):test.assert_equals(odd_even(n), 1)- for n in range(-100, 101, 2):
- test.assert_equals(odd_even(n), 0)
- @test.it("test case 2: Testing Odd Numbers")
- def test_case():
for n in range(1, 333, 2):test.assert_equals(odd_even(n), 0)- for n in range(-101, 101, 2):
- test.assert_equals(odd_even(n), 1)