Created
February 26, 2023 19:54
-
-
Save donkirkby/2510b38171880a89e4ee892d4e70089d to your computer and use it in GitHub Desktop.
Live Coding Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(a, n): | |
low = 0 | |
high = len(a) - 1 | |
while True: | |
mid = low + high // 2 | |
v = a[mid] | |
if v == n: | |
return mid | |
if n < v: | |
high = mid - 1 | |
return -1 | |
i = search([1, 2, 4], 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(a, n): | |
low = 0 | |
high = len(a) - 1 | |
while True: | |
mid = (low + high) // 2 | |
v = a[mid] | |
if v == n: | |
return mid | |
if n < v: | |
high = mid - 1 | |
else: | |
low = mid + 1 | |
return -1 | |
# i = search([1, 2, 4], 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from search import search | |
def test_middle(): | |
i = search([1, 2, 4], 2) | |
assert i == 1 | |
def test(): | |
i = search([1, 2, 4], 1) | |
assert i == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from search import search | |
def test_middle(): | |
i = search([1, 2, 4], 2) | |
assert i == 1 | |
def test_left(): | |
i = search([1, 2, 4], 1) | |
assert i == 0 | |
def test(): | |
i = search([1, 2, 4], 4) | |
assert i == 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle as t | |
t.fillcolor('green') | |
t.pensize(3) | |
t.begin_fill() | |
sides = 4 | |
for i in range(sides): | |
t.forward(100) | |
t.right(360/sides) | |
t.end_fill() | |
t.hideturtle() | |
t.done() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle as t | |
t.fillcolor('green') | |
t.pensize(3) | |
t.begin_fill() | |
sides = 5 | |
for i in range(300): | |
t.forward(50 + i*10) | |
t.right(360/sides*2 + 1) | |
t.end_fill() | |
t.hideturtle() | |
t.done() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment