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
# encoding: utf-8 | |
def parse_to_numlist(raw_data) | |
splited_data = raw_data.split(",") | |
parsed_data = splited_data.map do |word_num| | |
begin | |
Integer(word_num) | |
rescue | |
return [] | |
end |
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
-- $ ghc report7.hs | |
-- でコンパイルして実行してカンマ区切りの数値を標準入力で動きます | |
-- splitが必要なので,必要に応じて | |
-- cabal install split | |
-- してください | |
import Data.Char | |
import Data.List.Split | |
data DecryptMode = AlphabetMode | SymbolMode |
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
def parse(raw_data): | |
# カンマ区切りの文字列から数字のリストへparseします | |
# parseに失敗したらFlaseを返します.成功したらTrueと結果を返します | |
splited_data = raw_data.split(",") | |
parsed_data = [] | |
for word_num in splited_data: | |
try: | |
parsed_data.append(int(word_num)) | |
except: | |
return (False,[]) |
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
from itertools import permutations | |
from math import sqrt | |
with open("./report4/input4.txt") as f: | |
city_l = list(map(lambda x: list(map(lambda y: int(y),x.strip().split(" "))),f.readlines())) | |
city_t = list(map(lambda x: [0]+list(x)+[0], permutations(range(1,city_l[0][0])))) | |
t_d = list(map( lambda x:sum([ sqrt(sum(map(lambda a,b: (a-b)**2,city_l[x[i]+1],city_l[x[i+1]+1]))) for i in range(city_l[0][0])]) ,city_t)) | |
print(city_t[t_d.index(min(t_d))]) |
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
-- 2016/07/19 | |
-- デコレーター的なもの | |
-- 参考 : http://qiita.com/_rdtr/items/d3bc1a8d4b7eb375c368 | |
import Control.Monad | |
data Point a = Point a a deriving (Show) | |
add (Point ax ay) (Point bx by) = Point (ax+bx) (ay+by) | |
sub (Point ax ay) (Point bx by) = Point (ax-bx) (ay-by) |
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 python3 | |
# -*- coding:utf-8 -*- | |
# ライフゲームです | |
# 世代ごとにセルの状態を画像保存します | |
# ついでにconvertコマンドでgif化します | |
import numpy as np | |
import cv2 | |
import copy |
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
-- 2015/11/07 | |
-- 合成Simpson則で数値積分します | |
-- でも数値の扱いがまだ微妙 | |
import Data.Ratio | |
func x = x^2 | |
a = 0 | |
b = 1 |
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
-- 2015/07/15 | |
-- haskellでTSP | |
-- 都市訪問順をランダムに決定し,近傍を求めて良い結果の訪問順の近傍を求めて…という感じ | |
-- 並列分散処理の課題用ですが,まだこれは並列化してない | |
-- 近傍それぞれの計算を並列化できそう | |
-- あと初期都市訪問順も複数にして並列化 | |
-- 収束判定どうするよ | |
import Control.Monad | |
import System.Random |
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 Data.List | |
import Data.Ratio | |
import Control.Monad.Writer | |
tableau1 = [[14,1,2], | |
[8,1,1], | |
[18,3,1], | |
[0,-2,-1]] | |
tableau2 = [[8,1,-1,2], |
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
-- 2015/05/30 | |
-- 連立方程式をGauss-Jordan法で解きます | |
matrix = [[2,1,1,1,6], | |
[1,2,1,1,7], | |
[1,1,2,1,12], | |
[1,1,1,2,15]] | |
a = (length matrix) :: Int |
NewerOlder