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
| """ | |
| This script provides testing Anthropic's tool search functionality across multiple scenarios. | |
| REQUIRED: | |
| - pip install arcadepy | |
| - pip install anthropic | |
| - export ANTHROPIC_API_KEY=<your_anthropic_api_key> | |
| - export ARCADE_API_KEY=<your_arcade_api_key> | |
| """ |
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
| @objc func hitEnemy() { | |
| updateHealthBar() | |
| UIView.animate(withDuration: 0.25, animations: { | |
| self.enemy.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) // Scale the enemy down to 0.8 of its size over 1/4 of a second | |
| }) { _ in | |
| UIView.animate(withDuration: 0.25) { | |
| self.enemy.transform = .identity // Once the enemy is done scaling down in size, have it return to its original size over a period of 1/4 of a second | |
| } | |
| } | |
| } |
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
| enemy.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hitEnemy))) |
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 UIKit | |
| class ViewController: UIViewController { | |
| private var healthBar: UIProgressView! | |
| private var enemy: UIImageView! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| setUpSubviews() |
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 distributeItems(items: int, n: int): | |
| itemsPerTurn = [] | |
| j = 0 # current turn | |
| numOfItems = n*(n+1)//2 # number of items given during turn 0 | |
| while items >= numOfItems: | |
| items -= numOfItems | |
| itemsPerTurn.append(numOfItems) | |
| j += 1 | |
| numOfItems = n**2 * j + n*(n+1)//2 # number of items given during turn j | |
| return itemsPerTurn |
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
| Operation Example Big O Time Complexity | |
| Length: len(s) O(1) | |
| Add: s.add(2) O(1) | |
| Contains: x in/not in s O(1) | |
| Remove: s.remove(2) O(1) | |
| Discard: s.discard(2) O(1) | |
| Pop: s.pop() O(1) | |
| Clear: s.clear() O(1) | |
| Construct: set(iterable) O(length of iterable) |
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
| Operation Example Big O Time Complexity | |
| Index: dict[k] O(1) | |
| Assign: dict[k] = v O(1) | |
| Length: dict(lst) O(1) | |
| Pop: dict.pop(k) O(1) | |
| Pop item: dict.popitem() O(1) | |
| Get a value: dict.get(k) O(1) | |
| Get keys: dict.keys() O(1) | |
| Clear: dict.clear() O(1) |
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
| Operation Example Big O Time Complexity | |
| Index: lst[i] O(1) | |
| Assign: lst[i] = 2 O(1) | |
| Length: len(lst) O(1) | |
| Append: lst.append(i) O(1) | |
| Pop: lst.pop() O(1) | |
| Clear: lst.clear() O(1) | |
| Slice: lst[start:end] O(end - start) | |
| Extend: lst.extend(iterable) O(length of iterable) |
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
| class SortingAlgorithms: | |
| def quickSort(self, leftIndex, rightIndex, lst) -> int: | |
| def partition(leftIndex, rightIndex, lst): | |
| pivotElement = lst[(leftIndex + rightIndex) // 2] | |
| while leftIndex <= rightIndex: | |
| # Find element on the left of the partition that is greater than the partitionElement | |
| while lst[leftIndex] < pivotElement: | |
| leftIndex += 1 | |
| # Find element on the right of the partition that is less than the partitionElement | |
| while lst[rightIndex] > pivotElement: |
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
| class SortingAlgorithms: | |
| def mergeSort(self, lst): | |
| if len(lst) > 1: | |
| # Split part of the algorithm | |
| middle = len(lst) // 2 # floor division to find middle of the list | |
| leftList = lst[:middle] | |
| rightList = lst[middle:] | |
| self.mergeSort(leftList) # left side of the list | |
| self.mergeSort(rightList) # right side of the list |
NewerOlder