R

東日本大震災ビッグデータWS project 311に参加する その4

WS R

三日坊主で更新が止まってましたが,いろいろ試してはいたのです. 位置情報付きのtweetリスト作成プロジェクト 先週土曜日くらいからこういうことをやっていました.ただのデータ作成ではありますが,メンバーに恵まれて楽しく作業できました.@hiiragi1104…

日本地図の色分け

R

暇だったので久々にRで遊んでみた.たしか青木先生のところに日本地図データがあったことを思い出し,色塗り.参考にしたのは以下のサイト. http://aoki2.si.gunma-u.ac.jp/R/color-map.html http://ds0.cc.yamaguchi-u.ac.jp/~fukuyo/r-map.html http://d.…

なんとも不思議なポリアの壺問題

R

ポリアの壺モデルがあまりに不思議なのでメモ.ポリアの壺モデルとは無限の収容力がある壺に紅白2色のボールを1つずつ入れていて,その中から一つ取り出したときに赤が出れば赤を1つ追加,白が出れば白を一つ追加するというモデルである.これを繰り返し…

Rを使ってYahoo!乗換案内から運賃や所要時間,乗換回数を取得するコード書いた

R

(※追記あり) 数日前にスクレイピングという言葉を学び,とりあえずRでやってみた.まだまだ勉強途中なのでいろいろ間違ってるかもしれないし,計算速度もそんなに速くないのだけど,どなたか詳しい人ご教授ください.むしろもっと楽な方法があれば是非!内…

Project Euler Problem 19

1900年1月1日は月曜日である。 9月、4月、6月、11月は30日まであり、2月を除く他の月は31日まである。 2月は28日まであるが、うるう年のときは29日である。 うるう年は西暦が4で割り切れる年に起こる。しかし、西暦が400で割り切れず100で割り切れる年はうる…

Project Euler Problem 18

以下の三角形の頂点から下まで移動するとき、その数値の合計の最大値は23になる。 3 7 5 2 4 6 8 5 9 3 この例では 3 + 7 + 4 + 9 = 23 以下の三角形を頂点から下まで移動するとき、その最大の合計値を求めよ。 75 95 64 17 47 82 18 35 87 10 20 04 82 47 6…

Project Euler Problem 17

1 から 5 までの数字を英単語で書けば one, two, three, four, five であり、全部で 3 + 3 + 4 + 4 + 5 = 19 の文字が使われている。 では 1 から 1000 (one thousand) までの数字をすべて英単語で書けば、全部で何文字になるか。 注: 空白文字やハイフンを…

Project Euler Problem 16

2^15 = 32768 であり、これの各数字の合計は 3 + 2 + 7 + 6 + 8 = 26 となる。 同様にして、2^1000 の各数字の合計を求めよ。 久々にやる.こういうのは簡単だなぁ. library(gmp) a1 <- as.bigz(2^1000) b1 <- numeric() for(i in 1:302){ b1[i] <- as.nume…

Project Euler Problem 14

正の整数に以下の式で繰り返し生成する数列を定義する。 n → n/2 (n が偶数) n → 3n + 1 (n が奇数) 13からはじめるとこの数列は以下のようになる。 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 13から1まで10個の項になる。この数列はどのような数字からは…

Project Euler Problem 15

2 × 2 のマス目の左上からスタートした場合、引き返しなしで右下にいくルートは 6 つある。 では、20 × 20 のマス目ではいくつのルートがあるか。 はいはい,瞬殺.中高生でもやり方わかるよ.コラッツの問題は詰まりそうだったので先にこっちを仕上げてみた…

Project Euler Problem 13

以下の50桁の数字100個の総和の上位10桁を求めよ。 37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072…

Project Euler Problem 10

10以下の素数の和は2 + 3 + 5 + 7 = 17である. 200万以下の全ての素数の和を計算しなさい. これはエラトステネスの篩のおかげで瞬殺です.エラトステネス様様です. eratosthenes <- function(x){ x_0 <- (x-1)/2 d <- rep(TRUE, x_0) l <- (sqrt(x) - 1) / …

Project Euler Problem 8

以下の1000桁の数字から5つの連続する数字を取り出してその積を計算する。そのような積の中で最大のものの値はいくらか 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017…

Project Euler Problem 7

素数を小さい方から6つ並べると 2, 3, 5, 7, 11, 13 であり、6番目の素数は 13 である。 10001 番目の素数を求めよ。 もう問題は日本語訳でいいや.この問題は結局,今まで避けてきた素数列が必要となるのでそれをつくることを考える.とりあえず素数でない…

Project Euler Problem 6

The sum of the squares of the first ten natural numbers is, 1^(2) + 2^(2) + ... + 10^(2) = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^(2) = 55^(2) = 3025 Hence the difference between the sum of the sq…

Project Euler Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20? 単なる最小公倍数なのですぐにやり方はわかる…

Project Euler Problem 4

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. 結構悩んだあげくに力技で解く.…

Project Euler Problem 3

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? この問題,難しくてなかなか良い方法が思いつかなかったので,とりあえず頭から割っていくことに…. x <- 600851475143 p <- 1 for (i in …

Project Euler Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence w…

Project Euler Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. 一日一論文も三日坊主で続かない毎日ですが,思いつきでP…