Skip to content

Instantly share code, notes, and snippets.

View effective-light's full-sized avatar
🎯
Focusing

Effective Light effective-light

🎯
Focusing
View GitHub Profile
/*
* 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 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.
def bob_cipher(phrase: str, key: str) -> str:
"""
>>> bob_cipher("ANT", "BOB")
B25O25B18
"""
new_s = ""
for key_char, phrase_char in zip(key, phrase):
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:
@effective-light
effective-light / sorting.py
Last active June 19, 2017 21:05
Sorting Algorithms
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]
@effective-light
effective-light / practice.py
Last active June 19, 2017 21:04
148 exam practice
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))
public class Prime
{
public boolean isPrime(int n)
{
if ( n <= 1 )
return false;
for ( int i = 2; i < n; i++ )
{
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)
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:
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!" );
}