Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences

anonymous No title
PHP
yes()
anonymous No title
PHP
<?php
$input_lines = explode(' ', trim(fgets(STDIN)));
$pernum = $input_lines[0];
$linenum = $input_lines[1];
for ($i = 0; $i < $linenum; $i++) {
    $temp = explode(' ', trim(fgets(STDIN)));
    //$temp=explode(' ',explode(
    $temp1 = $temp[0];
    $temp2 = $temp[2];
    $temp3 = str_replace(array(' liar.', 'honest'), array('znz', 'zez'), $temp[5]);
    $ren[$i] = implode('', array($temp1, $temp3, $temp2));
}
//配列で重複している物を削除する 
$ren = array_unique($ren);
//キーが飛び飛びになっているので、キーを振り直す 
$ren = array_values($ren);
$linenum = count($ren);
//矛盾するかどうか? 
$mujun = false;
for ($i = 0; $i < $linenum; $i++) {
    $temp = explode('z', $ren[$i]);
    if ($temp[0] < $temp[2]) {
        $hoge = $temp[0];
        $temp[0] = $temp[2];
        $temp[2] = $hoge;
    }
    if ($temp[0] == $temp[2] && $temp[1] == 'n') {
        $mujun = true;
        break;
    }
    if (isset($record["$temp[0]" . ',' . "$temp[2]"])) {
        $mujun = true;
        break;
    } else {
        if ($temp[1] == 'e') {
            $record["$temp[0]" . ',' . "$temp[2]"] = 1;
        } else {
            $record["$temp[0]" . ',' . "$temp[2]"] = -1;
        }
    }
}
if ($mujun) {
    echo '-1';
} else {
    $res = $pernum - $linenum + 1;
    echo $res;
}
?>
anonymous No title
Python
print("aaaaaaaaaaaaaaaaaaa")
anonymous No title
PHP
<?php

try{
	//データベースへ接続
	$db = new PDO('msql:host=localhost;dbname=co_19_208_99sv_coco_com;charset=utf8','co-19-208.99sv-c','A8cjtYu3');

	//テーブルを作成する
	$sql = 'CREATE TABLE kadai2_test_table(
			number INT NOT NULL PRIMARY KEY,
			name VARCHAR(20) NOT NULL,
			message VARCHAR(100) NOT NULL,
			regist_timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
			)engine=innodb default charset=utf8';

	//SQL実行
	$res = $db->query($sql);

}catch(PDOException $e){
	echo "データベースに接続できません。".$e->getMessage();
	exit;
}

//接続を閉じる
$db = null;
	
?>
anonymous No title
Python
"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets


def phi3(x):
    return x[:, 0] * x[:, 1] * np.pi


def XI(x):
    return (np.sin(x[:, 1]) * (np.sin(phi3(x))) ** 2 + np.sin(x[:, 0]) * (np.cos(phi3(x))) ** 2 + np.cos(
        x[:, 0]) * np.cos(x[:, 1]) * np.sin(phi3(x))) * np.sin(x[:, 0]) / 4


def YI(x):
    return (-np.sin(x[:, 1]) * np.cos(x[:, 0]) * (np.sin(phi3(x))) ** 2 - np.cos(x[:, 0]) * np.sin(x[:, 0]) * (
        np.cos(phi3(x))) ** 2 + ((np.sin(x[:, 0])) ** 2) * np.cos(x[:, 1]) * np.sin(phi3(x))) / 4


def ZI(x):
    return np.cos(x[:, 0]) * np.cos(phi3(x)) / 4


def IX(x):
    return (np.sin(x[:, 0]) * (np.sin(phi3(x))) ** 2 + np.sin(x[:, 1]) * (np.cos(phi3(x))) ** 2 + np.cos(
        x[:, 0]) * np.cos(x[:, 1]) * np.sin(phi3(x))) * np.sin(x[:, 1]) / 4


def XX(x):
    return (((np.sin(x[:, 1])) ** 2) * (np.sin(phi3(x))) ** 2 + np.cos(x[:, 0]) * np.cos(x[:, 1]) * np.sin(phi3(x)) * (
            np.sin(x[:, 0]) + np.sin(x[:, 1]))) / 4


def YX(x):
    return (-np.sin(x[:, 0]) * np.cos(x[:, 0]) * (np.sin(x[:, 1])) ** 2 + np.sin(phi3(x)) * np.cos(x[:, 1]) * (
            np.sin(x[:, 0]) * np.sin(x[:, 1]) - np.cos(x[:, 0]) * np.cos(x[:, 0]))) / 4


def ZX(x):
    return (-np.sin(x[:, 0]) * np.cos(x[:, 1]) * np.sin(phi3(x)) + np.cos(x[:, 0]) * (np.sin(x[:, 1])) ** 2 + np.sin(
        x[:, 1]) * np.cos(x[:, 1]) * np.sin(phi3(x))) * np.cos(phi3(x)) / 4


def IY(x):
    return (-np.sin(x[:, 0]) * np.cos(x[:, 1]) * (np.sin(phi3(x))) ** 2 - np.sin(x[:, 1]) * np.cos(x[:, 1]) * (
        np.cos(phi3(x))) ** 2 + ((np.sin(x[:, 1])) ** 2) * np.cos(x[:, 0]) * np.sin(phi3(x))) / 4


def XY(x):
    return (-np.sin(x[:, 1]) * np.cos(x[:, 1]) * (np.sin(x[:, 0])) ** 2 + np.sin(phi3(x)) * np.cos(x[:, 0]) * (
            np.sin(x[:, 0]) * np.sin(x[:, 1]) - np.cos(x[:, 1]) * np.cos(x[:, 1]))) / 4


def YY(x):
    return (np.sin(x[:, 0]) * np.cos(x[:, 0]) * np.sin(x[:, 1]) * np.cos(x[:, 1]) - np.sin(phi3(x)) * (
            np.sin(x[:, 0]) * (np.cos(x[:, 1])) ** 2 + np.sin(x[:, 1]) * (np.cos(x[:, 0])) ** 2)) / 4


def ZY(x):
    return (-np.sin(x[:, 0]) * np.sin(phi3(x)) * np.cos(phi3(x)) - np.cos(x[:, 1]) * np.cos(x[:, 0]) * np.cos(
        phi3(x)) + np.sin(x[:, 1]) * np.cos(phi3(x)) * np.sin(phi3(x))) * np.sin(x[:, 1]) / 4


def IZ(x):
    return np.cos(x[:, 1]) * np.cos(phi3(x)) / 4


def XZ(x):
    return (-np.sin(x[:, 1]) * np.cos(x[:, 0]) * np.sin(phi3(x)) + np.cos(x[:, 1]) * (np.sin(x[:, 0])) ** 2 + np.sin(
        x[:, 0]) * np.cos(x[:, 0]) * np.sin(phi3(x))) * np.cos(phi3(x)) / 4


def YZ(x):
    return (-np.sin(x[:, 1]) * np.sin(phi3(x)) * np.cos(phi3(x)) - np.cos(x[:, 1]) * np.cos(x[:, 0]) * np.cos(
        phi3(x)) + np.sin(x[:, 0]) * np.cos(phi3(x)) * np.sin(phi3(x))) * np.sin(x[:, 0]) / 4


def ZZ(x):
    return np.cos(x[:, 1]) * np.cos(x[:, 0]) / 4


# import some data to play with
iris = datasets.make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, factor=0.8)

x = iris[0]  # circle point data
W = iris[1]
Y = 2 * W - 1  # label data


def my_kernel(x1, x2):
    p1 = get_p_array(x1)
    p2 = get_p_array(x2)
    return np.dot(p1.T, p2)


def get_p_array(x):
    const = np.full(x.shape[0], 1 / 4)
    return np.array(
        [const, XI(x), YI(x), ZI(x), IX(x), XX(x), YX(x), ZX(x), IY(x), XY(x), YY(x), ZY(x), IZ(x), XZ(x), YZ(x),
         ZZ(x)])


h = .02  # step size in the mesh

# we create an instance of SVM and fit out data.
clf = svm.SVC(kernel=my_kernel)
clf.fit(x, Y)

# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, x_max]x[y_min, y_max].
x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1
y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)

# Plot also the training points
plt.scatter(x[:, 0], x[:, 1], c=Y, cmap=plt.cm.Paired, edgecolors='k')
plt.title('3-Class classification using Support Vector Machine with custom'
          ' kernel')
plt.axis('tight')
plt.show()
anonymous No title
Python
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
import math

def phi3(x):
    return x[0]*x[1]*math.pi
def XI(x):
    return (math.sin(x[1])*(math.sin(phi3(x)))**2+math.sin(x[0])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[0])/4
def YI(x):
    return (-math.sin(x[1])*math.cos(x[0])*(math.sin(phi3(x)))**2-math.cos(x[0])*math.sin(x[0])*(math.cos(phi3(x)))**2+((math.sin(x[0]))**2)*math.cos(x[1])*math.sin(phi3(x)))/4
def ZI(x):
    return math.cos(x[0])*math.cos(phi3(x))/4
def IX(x):
    return (math.sin(x[0])*(math.sin(phi3(x)))**2+math.sin(x[1])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[1])/4
def XX(x):
    return (((math.sin(x[1]))**2)*(math.sin(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x))*(math.sin(x[0])+math.sin(x[1])))/4
def YX(x):
    return (-math.sin(x[0])*math.cos(x[0])*(math.sin(x[1]))**2+math.sin(phi3(x))*math.cos(x[1])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[0])*math.cos(x[0])))/4
def ZX(x):
    return (-math.sin(x[0])*math.cos(x[1])*math.sin(phi3(x))+math.cos(x[0])*(math.sin(x[1]))**2+math.sin(x[1])*math.cos(x[1])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def IY(x):
    return (-math.sin(x[0])*math.cos(x[1])*(math.sin(phi3(x)))**2-math.sin(x[1])*math.cos(x[1])*(math.cos(phi3(x)))**2+((math.sin(x[1]))**2)*math.cos(x[0])*math.sin(phi3(x)))/4
def XY(x):
    return (-math.sin(x[1])*math.cos(x[1])*(math.sin(x[0]))**2+math.sin(phi3(x))*math.cos(x[0])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[1])*math.cos(x[1])))/4
def YY(x):
    return (math.sin(x[0])*math.cos(x[0])*math.sin(x[1])*math.cos(x[1])-math.sin(phi3(x))*(math.sin(x[0])*(math.cos(x[1]))**2+math.sin(x[1])*(math.cos(x[0]))**2))/4
def ZY(x):
    return (-math.sin(x[0])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[1])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[1])/4
def IZ(x):
    return math.cos(x[1])*math.cos(phi3(x))/4
def XZ(x):
    return (-math.sin(x[1])*math.cos(x[0])*math.sin(phi3(x))+math.cos(x[1])*(math.sin(x[0]))**2+math.sin(x[0])*math.cos(x[0])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def YZ(x):
    return (-math.sin(x[1])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[0])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[0])/4
def ZZ(x):
    return math.cos(x[1])*math.cos(x[0])/4

# import some data to play with
iris = datasets.make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, factor=0.8)

x = iris[0]
W = iris[1]
Y = W+W-1


def my_kernel(A, B):
    b = np.zeros((A.shape[0], B.shape[0]))
    for i in range(0,A.shape[0]):
        for j in range(0,B.shape[0]):
            x=A[i]
            y=B[j]
            PX=np.array([1/4,XI(x),YI(x),ZI(x),IX(x),XX(x),YX(x),ZX(x),IY(x),XY(x),YY(x),ZY(x),IZ(x),XZ(x),YZ(x),ZZ(x)])
            PY=np.array([1/4,XI(y),YI(y),ZI(y),IX(y),XX(y),YX(y),ZX(y),IY(y),XY(y),YY(y),ZY(y),IZ(y),XZ(y),YZ(y),ZZ(y)])
            b[i][j] += np.dot(PX,PY)
    return b

h = .02  # step size in the mesh

# we create an instance of SVM and fit out data.
clf = svm.SVC(kernel=my_kernel)
clf.fit(x, Y)

# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, x_max]x[y_min, y_max].
x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1
y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)

# Plot also the training points
plt.scatter(x[:, 0], x[:, 1], c=Y, cmap=plt.cm.Paired, edgecolors='k')
plt.title('3-Class classification using Support Vector Machine with custom'
          ' kernel')
plt.axis('tight')
plt.show()
anonymous No title
Python
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
import math

def phi3(x):
    return x[0]*x[1]*math.pi
def XI(x):
    return (math.sin(x[1])*(math.sin(phi3(x)))**2+math.sin(x[0])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[0])/4
def YI(x):
    return (-math.sin(x[1])*math.cos(x[0])*(math.sin(phi3(x)))**2-math.cos(x[0])*math.sin(x[0])*(math.cos(phi3(x)))**2+((math.sin(x[0]))**2)*math.cos(x[1])*math.sin(phi3(x)))/4
def ZI(x):
    return math.cos(x[0])*math.cos(phi3(x))/4
def IX(x):
    return (math.sin(x[0])*(math.sin(phi3(x)))**2+math.sin(x[1])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[1])/4
def XX(x):
    return (((math.sin(x[1]))**2)*(math.sin(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x))*(math.sin(x[0])+math.sin(x[1])))/4
def YX(x):
    return (-math.sin(x[0])*math.cos(x[0])*(math.sin(x[1]))**2+math.sin(phi3(x))*math.cos(x[1])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[0])*math.cos(x[0])))/4
def ZX(x):
    return (-math.sin(x[0])*math.cos(x[1])*math.sin(phi3(x))+math.cos(x[0])*(math.sin(x[1]))**2+math.sin(x[1])*math.cos(x[1])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def IY(x):
    return (-math.sin(x[0])*math.cos(x[1])*(math.sin(phi3(x)))**2-math.sin(x[1])*math.cos(x[1])*(math.cos(phi3(x)))**2+((math.sin(x[1]))**2)*math.cos(x[0])*math.sin(phi3(x)))/4
def XY(x):
    return (-math.sin(x[1])*math.cos(x[1])*(math.sin(x[0]))**2+math.sin(phi3(x))*math.cos(x[0])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[1])*math.cos(x[1])))/4
def YY(x):
    return (math.sin(x[0])*math.cos(x[0])*math.sin(x[1])*math.cos(x[1])-math.sin(phi3(x))*(math.sin(x[0])*(math.cos(x[1]))**2+math.sin(x[1])*(math.cos(x[0]))**2))/4
def ZY(x):
    return (-math.sin(x[0])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[1])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[1])/4
def IZ(x):
    return math.cos(x[1])*math.cos(phi3(x))/4
def XZ(x):
    return (-math.sin(x[1])*math.cos(x[0])*math.sin(phi3(x))+math.cos(x[1])*(math.sin(x[0]))**2+math.sin(x[0])*math.cos(x[0])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def YZ(x):
    return (-math.sin(x[1])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[0])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[0])/4
def ZZ(x):
    return math.cos(x[1])*math.cos(x[0])/4

# import some data to play with
iris = datasets.make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, factor=0.8)

x = iris[0]
W = iris[1]
Y = W+W-1


def my_kernel(A, B):
    b = np.zeros((Y.shape[0], Y.shape[0]))
    for i in range(0,Y.shape[0]):
        for j in range(0,Y.shape[0]):
            x=A[i]
            y=B[j]
            PX=np.array([1/4,XI(x),YI(x),ZI(x),IX(x),XX(x),YX(x),ZX(x),IY(x),XY(x),YY(x),ZY(x),IZ(x),XZ(x),YZ(x),ZZ(x)])
            PY=np.array([1/4,XI(y),YI(y),ZI(y),IX(y),XX(y),YX(y),ZX(y),IY(y),XY(y),YY(y),ZY(y),IZ(y),XZ(y),YZ(y),ZZ(y)])
            b[i][j] += np.dot(PX,PY)
    return b

h = .02  # step size in the mesh

# we create an instance of SVM and fit out data.
clf = svm.SVC(kernel=my_kernel)
clf.fit(x, Y)

# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, x_max]x[y_min, y_max].
x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1
y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)

# Plot also the training points
plt.scatter(x[:, 0], x[:, 1], c=Y, cmap=plt.cm.Paired, edgecolors='k')
plt.title('3-Class classification using Support Vector Machine with custom'
          ' kernel')
plt.axis('tight')
plt.show()
anonymous No title
Python

"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
import math

def phi3(x):
    return x[0]*x[1]*math.pi
def XI(x):
    return (math.sin(x[1])*(math.sin(phi3(x)))**2+math.sin(x[0])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[0])/4
def YI(x):
    return (-math.sin(x[1])*math.cos(x[0])*(math.sin(phi3(x)))**2-math.cos(x[0])*math.sin(x[0])*(math.cos(phi3(x)))**2+((math.sin(x[0]))**2)*math.cos(x[1])*math.sin(phi3(x)))/4
def ZI(x):
    return math.cos(x[0])*math.cos(phi3(x))/4
def IX(x):
    return (math.sin(x[0])*(math.sin(phi3(x)))**2+math.sin(x[1])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[1])/4
def XX(x):
    return (((math.sin(x[1]))**2)*(math.sin(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x))*(math.sin(x[0])+math.sin(x[1])))/4
def YX(x):
    return (-math.sin(x[0])*math.cos(x[0])*(math.sin(x[1]))**2+math.sin(phi3(x))*math.cos(x[1])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[0])*math.cos(x[0])))/4
def ZX(x):
    return (-math.sin(x[0])*math.cos(x[1])*math.sin(phi3(x))+math.cos(x[0])*(math.sin(x[1]))**2+math.sin(x[1])*math.cos(x[1])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def IY(x):
    return (-math.sin(x[0])*math.cos(x[1])*(math.sin(phi3(x)))**2-math.sin(x[1])*math.cos(x[1])*(math.cos(phi3(x)))**2+((math.sin(x[1]))**2)*math.cos(x[0])*math.sin(phi3(x)))/4
def XY(x):
    return (-math.sin(x[1])*math.cos(x[1])*(math.sin(x[0]))**2+math.sin(phi3(x))*math.cos(x[0])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[1])*math.cos(x[1])))/4
def YY(x):
    return (math.sin(x[0])*math.cos(x[0])*math.sin(x[1])*math.cos(x[1])-math.sin(phi3(x))*(math.sin(x[0])*(math.cos(x[1]))**2+math.sin(x[1])*(math.cos(x[0]))**2))/4
def ZY(x):
    return (-math.sin(x[0])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[1])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[1])/4
def IZ(x):
    return math.cos(x[1])*math.cos(phi3(x))/4
def XZ(x):
    return (-math.sin(x[1])*math.cos(x[0])*math.sin(phi3(x))+math.cos(x[1])*(math.sin(x[0]))**2+math.sin(x[0])*math.cos(x[0])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def YZ(x):
    return (-math.sin(x[1])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[0])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[0])/4
def ZZ(x):
    return math.cos(x[1])*math.cos(x[0])/4

# import some data to play with
iris = datasets.make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, factor=0.8)

x = iris[0]
W = iris[1]
Y = W+W-1


def my_kernel(x, Y):
    PX=np.array([1/4,XI(x),YI(x),ZI(x),IX(x),XX(x),YX(x),ZX(x),IY(x),XY(x),YY(x),ZY(x),IZ(x),XZ(x),YZ(x),ZZ(x)])
    PY=np.array([1/4,XI(Y),YI(Y),ZI(Y),IX(Y),XX(Y),YX(Y),ZX(Y),IY(Y),XY(Y),YY(Y),ZY(Y),IZ(Y),XZ(Y),YZ(Y),ZZ(Y)])
    return np.dot(PX,PY)

h = .02  # step size in the mesh

# we create an instance of SVM and fit out data.
clf = svm.SVC(kernel=my_kernel)
clf.fit(x, Y)

# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, x_max]x[y_min, y_max].
x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1
y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)

# Plot also the training points
plt.scatter(x[:, 0], x[:, 1], c=Y, cmap=plt.cm.Paired, edgecolors='k')
plt.title('3-Class classification using Support Vector Machine with custom'
          ' kernel')
plt.axis('tight')
plt.show()
anonymous No title
PHP

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>編集画面</title>
</head>
	
<body>
	<form method="post" action="kadai_2_06.php">
		<div>
			<label for="pass">パスワード</label>
			<input type="password" name="pass" value="">
		</div>
		<div>
			<label for="editNo">編集番号</label>
			<input type="text" name="editNo" value="">
		</div>
		<input type="submit" name="btn_edit" value="編集">
	</form>
</body>
</html>
anonymous No title
PHP
<?php

// メッセージを保存するファイルのパス設定
define( 'FILENAME', './kadai_2_06.txt');

// タイムゾーン設定
date_default_timezone_set('Asia/Tokyo');

// 変数の初期化
$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();
$success_message = null;
$error_message = array();
$delete = null;
$del_con = null;
$del_data = array();

//----------------テキストファイルにデータを書き込む-----------------

if(file_exists(FILENAME)){
	$num = count(file(FILENAME)) + 1; 
}else{
	$num = 1;
}

if( isset($_POST['btn_submit']) ) {

	//-----未入力のバリデーション---------
	if(empty($_POST['view_name'])){
		echo '名前を入力してください!';
		exit();
	}
	
	if(empty($_POST['message'])){
		echo 'メッセージを入力してください!';
		exit();
	}
	
	if(empty($_POST['pass'])){
		echo 'パスワードを入力してください!';
		exit();
	}
	
	//------------------------------------
	
	if( $file_handle = fopen( FILENAME, "a") ) {	
		// タイムスタンプ
		$now_date = date("Y-m-d H:i:s");
	
		// 書き込むデータを作成
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date."<>".$_POST['pass']."<>"."\n";
	
		// 書き込み
		fwrite( $file_handle, $data); 
	
		// ファイルを閉じる
		fclose( $file_handle);
		
		//投稿が成功したことを示すメッセージ
		$success_message = 'メッセージを送信しました';
	}	
}

//----------------------------【編集】----------------------------------

//------①送信されてきた編集番号と一致する配列の値を取得------
if(isset($_POST['btn_edit'])){

	if((empty($_POST['editNo']))||(empty($_POST['pass']))){
		echo '編集番号とパスワードの両方を入力してください';
		exit();
	}
	
	$editNo = $_POST['editNo'];
	$edit_con = file(FILENAME);
	for( $j=0; $j<count($edit_con); $j++ ){
		$edit_data = explode("<>", $edit_con[$j]);
			if(($edit_data[4]==$_POST['pass'])&&($edit_data[0]==$editNo)){
				$edit_no = $edit_data[0];
				$edit_name = $edit_data[1];
				$edit_message = $edit_data[2];
				$edit_pass = $edit_data[4];
			}else if(($edit_data[0]==$editNo)&&($_POST['pass']!=$edit_data[4])){
				echo 'パスワードまたは編集番号が違います';
				exit();
			}	
	}
}

//-----------------②メッセージを編集する---------------------
if(isset($_POST['execute_edit'])){
	
	//新しいメッセージをテキストに書き込む
	$editNo = $_POST['keep_editNo'];
	$edit_con = file(FILENAME);
	$now_date = date("Y-m-d H:i:s");
	for( $k=0; $k<count($edit_con); $k++ ){
		$edit_data = explode("<>", $edit_con[$k]);
		if($edit_data[0] == $editNo){
			$edit_data[1] = $_POST['view_name'];
			$edit_data[2] = $_POST['message'];
			$edit_data[3] = $now_date;
			$edit_data[4] = $_POST['pass'];
			$edit_con[$k] = implode("<>",$edit_data)."\n";
			file_put_contents(FILENAME,$edit_con);
		}
	}				
}
//----------------【削除】指定した番号のメッセージを削除--------------------
if(isset($_POST['btn_delete'])){

	if((empty($_POST['deleteNo']))||(empty($_POST['pass']))){
		echo '削除番号とパスワードの両方を入力してください';
		exit();
	}

	$deleteNo = $_POST['deleteNo'];
	$del_con = file(FILENAME);
	
	for( $i=0; $i<count($del_con); $i++ ){
		$del_data = explode("<>", $del_con[$i]);
		if(($del_data[4]==$_POST['pass'])&&($del_data[0]==$deleteNo)){
			array_splice($del_con,$i,1); 
			for( $l=0; $l<count($del_con); $l++ ){
				$down = explode("<>",$del_con[$l]);
				if( $l>=$i ){
					$down[0] = $down[0] - 1;
					$del_con[$l]=implode("<>",$down); 
				}
			}
			file_put_contents(FILENAME,$del_con);
		}else if(($del_data[0]==$deleteNo)&&($del_data[4]!=$_POST['pass'])){
			echo 'パスワードまたは削除番号が違います';
			exit();
		}
	}
}

//-------テキストファイルのデータを掲示板のフォーム下に表示--------

if( $file_handle = fopen( FILENAME,'r') ) {
    
     while( $data = fgets($file_handle) ){	//fgets関数でファイルからデータを一行ずつ全て取得
		
		//preg_split関数で文字列を特定の文字で分割する:
		$split_data = explode("<>",$data);

        $message = array(
        	'post_no' => $split_data[0],
            'view_name' => $split_data[1],
            'message' => $split_data[2],
            'post_date' => $split_data[3]
        );
        array_unshift( $message_array, $message);
    }

    // ファイルを閉じる
    fclose( $file_handle);
}

?>

<!------------------------------<HTML>----------------------------------->

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>

<body>
<h2>簡易掲示板(^-^*)</h2>
	<?php if(!empty($success_message)):?>
		<p class="success_message"><?php echo $success_message;?></p>
	<?php endif; ?>
	
	<?php if(!empty($error_message)):?>
		<ul class="error_message">
			<?php foreach($error_message as $value):?>
				<li>・<?php echo $value; ?></li>
			<?php endforeach; ?>
		</ul>
	<?php endif; ?>
	
	<form method="post">
		<div>
			<label for="pass">パスワード</label>
			<input type="password" name="pass" value="<?php if(isset($_POST['btn_edit'])){ echo $edit_pass; } ?>">
		</div>
		<div>
			<label for="view_name">名前</label>
			<input type="text" name="view_name" value="<?php if(isset($_POST['btn_edit'])){ echo $edit_name; } ?>">
		</div>
		<div>
			<label for="message">メッセージ</label>
			<textarea name="message"><?php if(isset($_POST['btn_edit'])){ echo $edit_message; } ?></textarea>
			<input type="submit" name="btn_submit" value="投稿">
			<input type="hidden" name="keep_editNo" value="<?php if(isset($_POST['btn_edit'])){ echo $edit_no; } ?>">
			<input type="submit" name="execute_edit" value="編集">
		</div>
	</form>
	
	<form method="post" action="kadai_2_06_edit.html">
		<div>
			<input type="submit" name="btn_edit" value="投稿を編集">
		</div>	
	</form>
	
	<form method="post" action="kadai_2_06_delete.html">
		<div>
			<input type="submit" name="btn_delete" value="投稿を削除">
		</div>	
	</form>
		
<hr>
<!-------------------フォーム下に表示----------------------->
<section>
	<?php if( !empty($message_array) ): ?>
	<?php foreach( $message_array as $value ): ?>
	<article>
	    <div class="info">
	        <h2><?php echo $value['post_no'].":".$value['view_name']; ?></h2>
	        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
	    </div>
	    <p><?php echo $value['message']; ?></p>
	</article>
	<?php endforeach; ?>
	<?php endif; ?>
</section>
	
</body>
</html>