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
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
#define N 50 | |
#define M 1000 | |
int marbles = M; | |
int scores[N]; |
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
package network; | |
public class LocalAreaNetwork extends Network | |
{ | |
public static String whatAmI = "I am a LAN"; | |
public static int numCreated; | |
public int numNodes; | |
public char firstLetter = 'L'; |
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!" ); | |
} |
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
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
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
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
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
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 bob_cipher(phrase: str, key: str) -> str: | |
""" | |
>>> bob_cipher("ANT", "BOB") | |
B25O25B18 | |
""" | |
new_s = "" | |
for key_char, phrase_char in zip(key, phrase): |
NewerOlder