Skip to content

Instantly share code, notes, and snippets.

@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
###############################################################################
# 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 / 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.")
}
@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")
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
#######################################################
# Evaluating Quandl Data Quality
#
# [email protected] - Nov 2013
#######################################################
library(quantmod)
library(Quandl)
library(Rbbg)
library(XML)
namespace SideEffect
{
using System;
class Program
{
static void Main(string[] args)
{
// SideEffecty();
// Homework 1
// Color to Greyscale Conversion
//A common way to represent color images is known as RGBA - the color
//is specified by how much Red, Grean and Blue is in it.
//The 'A' stands for Alpha and is used for transparency, it will be
//ignored in this homework.
//Each channel Red, Blue, Green and Alpha is represented by one byte.
//Since we are using one byte for each color there are 256 different
#load @"..\packages\Deedle.0.9.12\Deedle.fsx"
#load @"..\packages\FSharp.Charting.0.90.5\FSharp.Charting.fsx"
// Please note that I had to use FSharp.Data.2.0.0-alpha as current stable version 1.1.10
// has a bug in CSV provider that disallows to load from more than 2 sources in one execution
#r @"..\packages\FSharp.Data.2.0.0-alpha2\lib\net40\FSharp.Data.dll"
#r @"..\packages\MathNet.Numerics.FSharp.2.6.0\lib\net40\MathNet.Numerics.FSharp.dll"
#r @"..\packages\MathNet.Numerics.2.6.2\lib\net40\mathnet.numerics.dll"
open Deedle
open System
#r @"\\psf\Home\Desktop\GitHub\eulersfsharp\src\Euler\bin\Debug\FSharp.Data.dll"
#r @"\\psf\Home\Desktop\GitHub\eulersfsharp\src\packages\MSDN.FSharpChart.dll.0.60\lib\MSDN.FSharpChart.dll"
#r "System.Windows.Forms.DataVisualization.dll"
open FSharp.Data
open MSDN.FSharp.Charting
open System.Windows.Forms
open System.Drawing
open System.Windows.Forms.DataVisualization.Charting