Skip to content

Instantly share code, notes, and snippets.

namespace SideEffect
{
using System;
class Program
{
static void Main(string[] args)
{
// SideEffecty();
#######################################################
# Evaluating Quandl Data Quality
#
# [email protected] - Nov 2013
#######################################################
library(quantmod)
library(Quandl)
library(Rbbg)
library(XML)
fun is_older (day1 : int*int*int, day2 : int*int*int) =
if (#1 day1) < (#1 day2)
then true
else if (((#2 day1) < (#2 day2)) andalso ((#1 day1) = (#1 day2)))
then true
else if (((#3 day1) < (#3 day2)) andalso ((#2 day1) = (#2 day2)) andalso ((#1 day1) = (#1 day2)))
then true
else false
@timmyshen
timmyshen / agecount.R
Created October 20, 2013 03:59
The goal of this part is to write a function called agecount that returns the number of homicide victims of a given age. For most (but not all) records there is an indication of the age of the victim. Your function should take one argument, the age of the victim(s), extract the age of the victim from each record and then return a count of the nu…
# agecount.R
agecount <- function(age = NULL) {
## Check that "age" is non-NULL; else throw error
if (is.null(age)) {
stop("Age input cannot be NULL")
}
## Read "homicides.txt" data file
homicides <- readLines("homicides.txt")
@timmyshen
timmyshen / count.R
Created October 20, 2013 03:57
Write a function named count that takes one argument, a character string indicating the cause of death. The function should then return an integer representing the number of homicides from that cause in the dataset. If no cause of death is specied, then the function should return an error message via the stop function.
# count.R
# setwd("~/ComputingForDataAnalysis/Assignment4")
count <- function(cause = NULL) {
## Check that "cause" is non-NULL; else throw error
if (is.null(cause)) {
stop("Cause has not been specified.")
}
###############################################################################
# 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.
@timmyshen
timmyshen / rpsls.py
Created October 18, 2013 21:22
Mini-project description — Rock-paper-scissors-lizard-Spock
# Rock-paper-scissors-lizard-Spock
# The key idea of this program is to equate the strings
# "rock", "paper", "scissors", "lizard", "Spock" to numbers
# as follows:
#
# 0 - rock
# 1 - Spock
# 2 - paper
# 3 - lizard
<!DOCTYPE html>
<meta charset="utf-8">
<style>
div.tooltip {
position: absolute;
text-align: right;
z-index:9999;
width: 6px;
height: 18px;
.DS_STORE
@timmyshen
timmyshen / number_before_reaching_sum.sml
Last active August 16, 2018 14:31
Write a function number_before_reaching_sum that takes an int called sum, which you can assume is positive, and an int list, which you can assume contains all positive numbers, and returns an int. You should return an int n such that the rst n elements of the list add to less than sum, but the rst n + 1 elements of the list add to sum or more. A…
fun number_before_reaching_sum (sum : int, xs : int list) =
if null xs then 0
(*else if null (tl xs) then 1*)
else if hd xs > sum then 0
else
let fun helper (i : int, partial_sum : int, tl_xs : int list) =
if partial_sum < 0 then i
else
helper(i + 1, partial_sum - hd tl_xs, tl tl_xs)
in