Download src/llm_benchmark/control/double.py from Prabodini/Test01: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/spaces/Prabodini/Test01/resolve/main/src/llm_benchmark/control/double.py
- Command line
-
hf download hf://spaces/Prabodini/Test01/src/llm_benchmark/control/double.py
-
curl -L -o double.py https://huggingface.co/spaces/Prabodini/Test01/resolve/main/src/llm_benchmark/control/double.py
2.34 kB
| from typing import List | |
| class DoubleForLoop: | |
| def sum_square(n: int) -> int: | |
| """Sum of squares of numbers from 0 to n (exclusive) | |
| Args: | |
| n (int): Number to sum up to | |
| Returns: | |
| int: Sum of squares of numbers from 0 to n | |
| """ | |
| sum_ = 0 | |
| for i in range(n): | |
| for j in range(n): | |
| if i == j: | |
| sum_ += i * j | |
| return sum_ | |
| def sum_triangle(n: int) -> int: | |
| """Sum of triangle of numbers from 0 to n (exclusive) | |
| Args: | |
| n (int): Number to sum up to | |
| Returns: | |
| int: Sum of triangle of numbers from 0 to n | |
| """ | |
| sum_ = 0 | |
| for i in range(n): | |
| for j in range(i + 1): | |
| sum_ += j | |
| return sum_ | |
| def count_pairs(arr: List[int]) -> int: | |
| """Count pairs of numbers in an array | |
| A pair is defined as exactly two numbers in the array that are equal. | |
| Args: | |
| arr (List[int]): Array of integers | |
| Returns: | |
| int: Number of pairs in the array | |
| """ | |
| count = 0 | |
| for i in range(len(arr)): | |
| ndup = 0 | |
| for j in range(len(arr)): | |
| if arr[i] == arr[j]: | |
| ndup += 1 | |
| if ndup == 2: | |
| count += 1 | |
| return count // 2 | |
| def count_duplicates(arr0: List[int], arr1: List[int]) -> int: | |
| """Count duplicates between two arrays | |
| Args: | |
| arr0 (List[int]): Array of integers | |
| arr1 (List[int]): Array of integers | |
| Returns: | |
| int: Number of duplicates between the two arrays | |
| """ | |
| count = 0 | |
| for i in range(len(arr0)): | |
| for j in range(len(arr1)): | |
| if i == j and arr0[i] == arr1[j]: | |
| count += 1 | |
| return count | |
| def sum_matrix(m: List[List[int]]) -> int: | |
| """Sum of matrix of integers | |
| Args: | |
| m (List[List[int]]): Matrix of integers | |
| Returns: | |
| int: Sum of matrix of integers | |
| """ | |
| sum_ = 0 | |
| for i in range(len(m)): | |
| for j in range(len(m[i])): | |
| sum_ += m[i][j] | |
| return sum_ | |