Skip to content

Instantly share code, notes, and snippets.

View roger35972134's full-sized avatar

Roger Wang roger35972134

View GitHub Profile
def get_length(dna):
lengh=len(dna)
return lengh
def is_longer(dna1, dna2):
""" (str, str) -> bool
Return True if and only if DNA sequence dna1 is longer than DNA sequence
dna2.
@roger35972134
roger35972134 / python_hw2
Created May 11, 2015 16:45
第二次python作業
def main():
列出巴斯卡三角形()
畫出二項分佈()
畫出巴松分佈()
def 列出巴斯卡三角形():
Z=[[bCoef(n,k) for k in range(n+1)] for n in range(20)]
for z in Z: print(z)
import itertools
def main():
print(__doc__)
排假(1, True)
排假(2, True)
排假(3)
排假(4)
from matplotlib import pyplot
from collections import namedtuple
from pprint import pprint as pp
from math import floor
#由於有點摸不著頭緒,所以參考了一下同學的程式碼,我下次會更多自己的想法
Stem = namedtuple('Stem', 'data, leafdigits')
data0 = Stem((4285,564,1278,205,3920,
2066,604,209,602,1379,
2584,14,349,3770,99,
# Tetromino for Idiots
# By Al Sweigart al@inventwithpython.com
# http://inventwithpython.com/pygame
# Released under a "Simplified BSD" license
import random, time, pygame, sys
from pygame.locals import *
偵數 = 25
視窗寬度 = 640
@roger35972134
roger35972134 / udn_news_crawler.rb
Last active September 27, 2017 07:41
crawler preparation for NEWS analysis
require 'nokogiri'
require 'open-uri'
# Let's try to fetch and parse HTML document
books = Nokogiri::HTML(open('https://udn.com/rank/pv/2/0/1'))
news = []
i = 0
@roger35972134
roger35972134 / Leetcode_3:time_limit.rb
Created October 11, 2017 06:00
Leetcode 3. Longest Substring Without Repeating Characters, but it failed by Submission Result: Time Limit Exceeded
# @param {String} s
# @return {Integer}
# ----------time limit-------------
def length_of_longest_substring(s)
longest_length = 0
for i in 0..s.length-1
check = []
for j in i..s.length-1
unless check.include? s[j]
check.push s[j]
# @param {String} s
# @return {Integer}
def length_of_longest_substring(s)
max = 0
for i in 0..s.length-1
check = Array.new(256, false)
for j in i..s.length-1
index = s[j].ord
if check[index] == false
def length_of_longest_substring(s)
max = 0
start_index = -1
char_to_index_map = {}
s.chars.each_with_index do |c, i|
if current_index = char_to_index_map[c] and current_index > start_index # if current_index != nil
start_index = current_index
end
class Currency < ActiveRecord::Base
require 'open-uri'
def self.get_currency
begin
books = Nokogiri::HTML(open("https://www.coingecko.com/en"))
name = []
abbreviation = []
rate = []
exchange = []