Skip to content

Instantly share code, notes, and snippets.

View elainechan's full-sized avatar

Elaine Chan elainechan

  • New York, New York
View GitHub Profile
def crackle_pop():
for i in range (1, 101):
if i % 15 == 0:
print("CracklePop")
elif i % 3 == 0:
print("Crackle")
elif i % 5 == 0:
print("Pop")
else:
print(i)
@elainechan
elainechan / europe.R
Created November 17, 2017 06:25 — forked from halhen/europe.R
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)
'''
rangoli.py
Design a function that prints an alphabet rangoli of size n.
Input: An integer n where: 0 < n < 27
Output: Print the alphabet rangoli.
The center of the rangoli has the first alphabet letter a,
The boundary has the last alphabet letter indicated.
'''
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<title>erdos d3 visualizations</title>
</head>
<body>
<svg class="chart"></svg>
<script type="text/javascript">
@elainechan
elainechan / rangolin.py
Last active August 16, 2016 18:21
Solution to Codjo problem 3
'''
rangolin.py
Design a function that prints an alphabet rangoli of size n.
Input: You are given an integer n where: 0 < n < 27
Output: Print the alphabet rangoli in the format explained above.
The center of the rangoli has the first alphabet letter a,
and the boundary has the last alphabet letter indicated
(in alphabetical order).
'''
@elainechan
elainechan / evenfib.py
Created July 6, 2016 10:16
Find the sum of even-valued terms in a Fibonacci sequence, where the sum should not exceed 100,000.
# Find the sum of even-valued terms in a Fibonacci sequence
# the sum should not exceed 100000
def even_sum(max):
# make Fibonacci list
a, b = 0, 1
a, b = b, a+b
fib = [b]
# make the even-number list
@elainechan
elainechan / fsi.r
Last active June 5, 2016 01:44
Scrape data from CSV files, clean the data, and visualize the data
setwd("/Users/elaine.chan/Documents/Workdocs/Election/BankrateFSI/")
library(foreign)
# make new data frames by selecting columns and adding Date column
add_id <- function(df, filename, dirname) {
year <- dirname
month <- substr(filename, 9, 10)
new_df <- cbind(
data.frame(
Date=rep(as.numeric(paste(year, month, sep='')), nrow(df))
), df)
setwd("/Users/elaine.chan/Documents/Workdocs/Election/BankrateFSI/")
library(foreign)
# make new data frames by selecting columns and adding Date column
add_id <- function(df, filename, dirname) {
year <- dirname
month <- substr(filename, 9, 10)
new_df <- cbind(
data.frame(
Date=rep(as.numeric(paste(year, month, sep='')), nrow(df))
), df)
StdinNotImplementedError Traceback (most recent call last)
<ipython-input-22-3f40b6e2b468> in <module>()
1 #Find the cube root of a perfect cube
----> 2 x = int(input('Enter an integer: '))
3 ans = 0
4 while ans**3 < abs(x):
5 ans = ans + 1
/Users/my.name/anaconda/lib/python3.5/
site-packages/ipykernel/kernelbase.py in raw_input(self, prompt)
x = int(input('Enter an integer: '))
ans = 0
while ans**3 < abs(x):
ans = ans + 1
if ans**3 != abs(x):
print (x, 'is not a perfect cube')
else:
if x < 0:
ans = -ans
print ('Cube root of', x,'is', ans)