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
# Homework 1 - Part 1 | |
def palindrome?(string) | |
string = string.downcase.gsub(/\W/, '') | |
string == string.reverse | |
end | |
def count_words(string) | |
Hash[ | |
string.downcase.scan(/\w+/). | |
group_by{|s| s}. |
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
//* ------------------------------------------------------------------------ | |
//* Rfc822DateTimeParser - Parse Date-Time In RFC-822 Format | |
//* Copyright (C) 2009 Tom Dong | |
//* | |
//* This library is free software; you can redistribute it and/or | |
//* modify it under the terms of the GNU Lesser General Public | |
//* License as published by the Free Software Foundation; either | |
//* version 2.1 of the License, or (at your option) any later version. | |
//* ------------------------------------------------------------------------ |
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
#!/usr/bin/ruby | |
############# Day 1 ############# | |
# Print the string “Hello, world.” | |
puts 'Hello, world' | |
# For the string “Hello, Ruby”, find the index of the word“Ruby”. | |
puts 'Hello, Ruby'.index('Ruby') |
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
;; http://www.cs.brown.edu/courses/csci1730/2012/Assignments/Interpreter/ | |
#lang plai | |
(define-type Binding | |
[binding (name symbol?) (named-expr CFWAE?)]) | |
(define-type CFWAE | |
[num (n number?)] | |
[binop (op procedure?) (lhs CFWAE?) (rhs CFWAE?)] |
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
// Example: distinguishing between vowels and consonants | |
val corpus = | |
Seq( // I swear these are all English words | |
"antidisestablishmentarian", "ablutophobia", "automatonophobia", "autotonsorialist", | |
"arachibutyrophobia", "automysophobia", "batrachophagous", "ballistocardiograph", | |
"blandiloquence", "brachydactylous", "bathythermograph", "cacodemomania", | |
"caesaropapism", "catapedamania", "cheiloproclitic", "chronosynchronicity", | |
"dendrochronology", "deorsumversion", "dermatoglyphics", "dolichocephalic", | |
"dysmorphophobia", "eellogofusciouhipoppokunurious", "electroencephalograph", "epiphenomenalism", |
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
using System.Text; | |
public class BinaryCode | |
{ | |
public string[] decode(string message) | |
{ | |
int[] messageInts = new int[message.Length]; | |
{ | |
for (int i = 0; i < message.Length; i += 1) | |
messageInts[i] = message[i] - '0'; |
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
#!/usr/bin/env scalas | |
!# | |
/*** | |
libraryDependencies ++= Seq( | |
"org.apache.commons" % "commons-lang3" % "3.1", | |
"com.github.scopt" %% "scopt" % "2.1.0" | |
) | |
resolvers += "sonatype-public" at "https://oss.sonatype.org/content/groups/public" |
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
import java.util | |
import weka.core.{DenseInstance, Attribute, Instances} | |
import scala.collection.convert.wrapAll._ | |
// 1. set up attributes | |
val atts = { | |
// numeric | |
val att1 = new Attribute("att1") | |
// nominal | |
val att2 = new Attribute("att2", (1 to 5).map("val" + _)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
import itertools,sys | |
class WinterAndPresents: | |
def getNumber(self, apple, orange): | |
"""This is an O(N) solution to SRM 601 Div 1 Problem 250. | |
The derivation is as follows. | |
Let :math:`a_i` and :math:`o_i` be the number of apples and oranges in bag :math:`i`, respectively. | |
Let :math:`x_m` denote the largest possible value of :math:`x`. | |
Given any :math:`x`, the number of different presents :math:`n(x)` can be written as: |
OlderNewer