This file contains 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 __future__ import annotations | |
from dataclasses import dataclass | |
from typing import Union | |
from enum import Enum | |
from random import choice | |
@dataclass | |
class Item: | |
name: str |
This file contains 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 chessBoardCellColor(cell1: str, cell2: str) -> bool: | |
""" | |
Given two cells on the standard chess board, | |
determines whether they have the same color or not. | |
""" | |
def _get_color(cell: str) -> str: | |
# Cells are a letter and a number. | |
# If letter is even index, blacks = even, whites = odd. | |
# If letter is odd index, blacks = odd, whites = even. |
This file contains 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 fizzbuzz(n: int) -> None: | |
""" | |
Prints out a series of numbers, 1 to n (inclusive), following these rules: | |
If n is divisible by 2, print 'fizz' | |
If n is divisible by 3, print 'buzz' | |
If both apply, print 'fizzbuzz' | |
If neither, print the number. | |
""" | |
This file contains 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 collections import namedtuple | |
def find_max_area(heights: list, debug=False) -> int: | |
Point = namedtuple('Point', ['x', 'y']) | |
distance = lambda p2, p1: p2.x - p1.x if p2.x >= p1.x else p1.x - p2.x | |
move_point = lambda point, increment: Point(point.x + increment, heights[point.x + increment]) | |
# Calculate area based on distance between lowest heights. | |
calc_max_area = lambda p2, p1: min(p2.y, p1.y) * distance(p2, p1) | |
This file contains 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
const verify_v4_numHosts = [ | |
{input: 0, output: 4294967294}, | |
{input: 1, output: 2147483646}, | |
{input: 2, output: 1073741822}, | |
{input: 3, output: 536870910}, | |
{input: 4, output: 268435454}, | |
{input: 5, output: 134217726}, | |
{input: 6, output: 67108862}, | |
{input: 7, output: 33554430}, | |
{input: 8, output: 16777214}, |
This file contains 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
jinhai@seanc-VirtualBox ~/d/cs4251-project> ./client 127.0.0.1 9999 | |
Welcome to the Internet Time and Weather Service (ITWS). | |
Please select an option below: | |
1) Get current server time | |
2) Get current weather at server location | |
3) Quit | |
1 | |
The current server time is: Fri Nov 20 20:07:35 2015 |
This file contains 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
jinhai@seanc-VirtualBox:~/dev/cs4251-project$ cat server.log | |
[Server] Opening socket on port 9999. | |
[Client 127.0.0.1:38686] Connected. | |
[Client 127.0.0.1:38687] Connected. | |
[Client 127.0.0.1:38688] Connected. | |
[Client 127.0.0.1:38686] Q: What time is it? | |
[Client 127.0.0.1:38686] A: Fri Nov 20 19:54:07 2015 | |
[Client 127.0.0.1:38687] Q: What's the weather? | |
[Client 127.0.0.1:38687] A: Mostly sunny, 10 degrees Celsius | |
[Client 127.0.0.1:38687] Q: What time is it? |
This file contains 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
while True: | |
if cate.water_level is 0: | |
return # Class is over | |
cate.drink() |
This file contains 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
Plot[{ | |
PDF[NormalDistribution[Mean[sample0], StandardDeviation[sample0]], | |
x]/150, | |
PDF[NormalDistribution[Mean[base], StandardDeviation[base]], x]/150, | |
}, {x, 0.20590695205165493`, 0.3019270479483451`}, | |
PlotRange -> Full, Axes -> {True, True}] |
This file contains 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
#!/bin/bash | |
NUM_SAMPLES=50 | |
echo "The following runtime deltas are reported in seconds." | |
echo "Collecting $NUM_SAMPLES samples..." | |
# Build project from scratch each time. | |
prepare_build() { | |
make clean | |
make all |
NewerOlder