L
Size: a a a
R
L
import random
from itertools import tee
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
return zip(a, b)
def is_sorted_descending(c):
for a, b in pairwise(c):
if a < b:
return False
return True
def main():
c = [random.randint(1, 100) for _ in range(10)]
while not is_sorted_descending(c):
random.shuffle(c)
print(c)
if __name__ == "__main__":
main()
R
arr = {1, 2, 3}
bool check = new bool[arr.len]
while check.Aggregate((x,y) => x && y):
_if(!check[arr.len] && predicat(arr[rand(arr.len))
{
__check[arr.len] = true;
__yield arr[arr.len];
}
L
import dataclasses
import math
import random
@dataclasses.dataclass
class Point:
x: float
y: float
associated_value: float
def rotate_counter_clockwise(self, degrees):
rads = degrees * math.pi / 180
x = self.x
y = self.y
self.x = x * math.cos(rads) - y * math.sin(rads)
self.y = x * math.sin(rads) + y * math.cos(rads)
def main():
the_matrix = [
Point(x, y, random.randint(-100, 100))
for x in range(4)
for y in range(4)
]
for p in the_matrix:
p.rotate_counter_clockwise(-45)
diagonal = [p.associated_value for p in the_matrix if math.isclose(p.y, 0, abs_tol=0.001)]
print("Diagonal is", diagonal)
print([n for n in diagonal if n > 0])
if __name__ == "__main__":
main()
s