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 program is free software; you can redistribute it and/or | |
| * modify it under the terms of the GNU General Public License | |
| * as published by the Free Software Foundation; either version 3 | |
| * of the License, or (at your option) any later version. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. |
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 program is free software; you can redistribute it and/or | |
| * modify it under the terms of the GNU General Public License | |
| * as published by the Free Software Foundation; either version 3 | |
| * of the License, or (at your option) any later version. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. |
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 bob_cipher(phrase: str, key: str) -> str: | |
| """ | |
| >>> bob_cipher("ANT", "BOB") | |
| B25O25B18 | |
| """ | |
| new_s = "" | |
| for key_char, phrase_char in zip(key, phrase): |
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 pow_r(x, n): | |
| if n == 0: | |
| return 1 | |
| return multiply(x, pow_r(x, n - 1)) | |
| def multiply(f1, f2): | |
| def _multiply(a, b): | |
| if b == 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
| def selection_sort(lst): | |
| for i in range(len(lst) - 1): | |
| min_index = i | |
| for j in range(i + 1, len(lst)): | |
| if lst[j] < lst[min_index]: | |
| min_index = j | |
| lst[i], lst[min_index] = lst[min_index], lst[i] |
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 BTNode: | |
| def __init__(self, value=None, left=None, right=None): | |
| self.value, self.left, self.right = value, left, right | |
| def count_leaves(root: 'BTNode') -> int: | |
| """ Return the number of leaves in the tree rooted at root. | |
| >>> count_leaves(None) | |
| 0 | |
| >>> count_leaves(BTNode(0, None, None)) |
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
| public class Prime | |
| { | |
| public boolean isPrime(int n) | |
| { | |
| if ( n <= 1 ) | |
| return false; | |
| for ( int i = 2; i < n; i++ ) | |
| { |
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 stack import Stack | |
| def size(stk: Stack) -> int: | |
| """ Return the number of items on Stack stk, *without* modifying stk. | |
| (It’s OK if the contents of stk are modified during the execution of this | |
| function, as long as everything is restored before the function returns.) | |
| >>> st = Stack() | |
| >>> st.push(3); st.push(2); st.push(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
| def calc_exp(b: int, n: int) -> int: | |
| """ | |
| >>> calc_exp(10, 1) | |
| 21 | |
| >>> calc_exp(3, 4) | |
| 960 | |
| """ | |
| def _calc_exp(p: int) -> int: | |
| if p == 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
| public class ParseTest | |
| { | |
| public static void main(String[] args) | |
| { | |
| if ( args.length == 1 ) | |
| System.out.println( ParseTest.parseInt( args[0] ) ); | |
| else | |
| System.out.println( "Please supply an argument!" ); | |
| } |