Skip to content

Instantly share code, notes, and snippets.

View nafu's full-sized avatar
🧗
Keep exploring

Fumiya Nakamura nafu

🧗
Keep exploring
View GitHub Profile
# 6.00x Problem Set 5
#
# Part 2 - RECURSION
#
# Problem 3: Recursive String Reversal
#
def reverseString(aStr):
"""
Given a string, recursively returns a reversed copy of the string.
# 6.00x Problem Set 5
#
# Part 1 - HAIL CAESAR!
import string
import random
WORDLIST_FILENAME = "words.txt"
# -----------------------------------
@nafu
nafu / ps4a.py
Created March 2, 2013 21:03
Word Game
# 6.00x Problem Set 4A Template
#
# The 6.00 Word Game
# Created by: Kevin Luu <luuk> and Jenna Wiens <jwiens>
# Modified by: Sarina Canelake <sarina>
#
#
# Implemented by: Fumiya Nakamura <nafu>
#
@nafu
nafu / ps3_hangman.py
Created February 22, 2013 17:48
Hangman game
# 6.00 Problem Set 3
#
# Hangman game
#
# -----------------------------------
# Helper code
# You don't need to understand this helper code,
# but you will have to know how to use the functions
# (so be sure to read the docstrings!)
<!DOCTYPE HTML>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<title>D3Circle</title>
</head>
<body>
<div id="D3line"></div>
<script type="text/javascript">
@nafu
nafu / index.html
Last active December 14, 2015 01:39
<!DOCTYPE HTML>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<title>D3line</title>
</head>
<body>
<div id="D3line"></div>
<script type="text/javascript">
@nafu
nafu / gcdIter.py
Last active December 14, 2015 01:09
A clever mathematical trick (due to Euclid) makes it easy to find greatest common divisors. Suppose that a and b are two positive integers: ・If b = 0, then the answer is a ・Otherwise, gcd(a, b) is the same as gcd(b, a % b) See this website for an example of Euclid's algorithm being used to find the gcd. http://en.wikipedia.org/wiki/Euclidean_alg…
def gcdIter(a, b):
'''
a, b: positive integers
returns: a positive integer, the greatest common divisor of a & b.
'''
testValue = min(a, b)
# Keep looping until testValue divides both a & b evenly
while a % testValue != 0 or b % testValue != 0:
@nafu
nafu / min_temp.sh
Last active December 13, 2015 22:28
#!/bin/sh
# read data
sed -n '9,38p' weather.dat | \
# check min
awk 'NR==1{min=100} min > $3{min=$3; print min}' | \
# print the minimum value
tail -n 1
# below data is for learning
@nafu
nafu / football.dat
Last active December 13, 2015 22:28
Source <a
href="http://sunsite.tut.fi/rec/riku/soccer_data/tab/93_94/table.eng0.01_02.html">sunsite.tut.fi/rec/riku/soccer_data/tab/93_94/table.eng0.01_02.html</a>
<pre>
Team P W L D F A Pts
1. Arsenal 38 26 9 3 79 - 36 87
2. Liverpool 38 24 8 6 67 - 30 80
3. Manchester_U 38 24 5 9 87 - 45 77
4. Newcastle 38 21 8 9 74 - 52 71
5. Leeds 38 18 12 8 53 - 37 66
@nafu
nafu / chop.py
Last active December 13, 2015 21:38
def chop(target, search_array):
if target in search_array:
return search_array.index(target)
else:
return -1