Skip to content

Instantly share code, notes, and snippets.

@macrat
macrat / A.cpp
Last active August 29, 2015 14:23
昨日のICPCの解答。一応リファクタリングしてある。Bのチェック関数が荒っぽすぎて何か嫌だ。
#include <iostream>
using namespace std;
int main()
{
int num, min, max;
while(true)
@macrat
macrat / gist:aa3ef84295f6eed8b225
Created June 29, 2015 06:19
飛び交うカーソル。
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int main()
{
Display *dpy = XOpenDisplay(NULL);
int w = WidthOfScreen(XDefaultScreenOfDisplay(dpy));
int h = HeightOfScreen(XDefaultScreenOfDisplay(dpy));
int x=0, y=0;
@macrat
macrat / 上下に二つ.lua
Created August 6, 2015 12:54
rigidchipsのヘリ二種
Val
{
TRIM(min=-20, max=20)
ENGINE()
ENGINE_TOP()
ENGINE_BOTTOM()
}
Key
{
@macrat
macrat / aoj0510.c
Last active September 25, 2015 10:46
AOJの問題をがんばってといた。 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0510
#include <stdio.h>
int main(int argc, char** argv){
return printf("%d\n", (scanf("%d %d %d %d\n%d %d %d %d", &(&argc)[0], &(&argc)[-1], &(&argc)[-2], &(&argc)[-3], &(&argc)[-4], &(&argc)[-5], &(&argc)[-6], &(&argc)[-7]) == 8) ? ((((&argc)[0] += (&argc)[-1] + (&argc)[-2] + (&argc)[-3]) > ((&argc)[-4] += (&argc)[-5] + (&argc)[-6] + (&argc)[-7])) ? (&argc)[0] : (&argc)[-4]) : -1) == 0;
}
@macrat
macrat / neural.py
Last active October 9, 2015 07:38
ホップフィールドネットワークとやらを試してみた。hogeがhmgeになった。かなしい。
import numpy
def str2matrix(string):
return numpy.matrix(tuple(int(x)*2-1 for x in ''.join('{0:08b}'.format(ord(x)) for x in string))).T
def matrix2box(matrix):
return matrix * matrix.T - numpy.identity(matrix.shape[0])
def make_neural(*strings):
@macrat
macrat / search.c
Created October 23, 2015 03:42
昨日のプログラミングの講義の課題らしいです。
#include <stdio.h>
int main(int argc, char** argv){
char* itr = argv[2];
while(itr = strstr(itr, argv[1]))
printf("%d\n", (int)(++itr-argv[2]));
return 0;
}
@macrat
macrat / counter.sh
Created November 11, 2015 13:13
シェルスクリプトでCGIカウンター的なやつ。flock便利!
#!/bin/bash
file='count.log'
flock ${file} sh -c "expr `cat ${file} 2>/dev/null` + 1 >${file}; echo -e \"Content-Type: text/plain\n`cat ${file}`\""
@macrat
macrat / all-one.cu
Created November 13, 2015 06:10
GPUを使って全部1の遺伝子を目指してみた。
#include <stdio.h>
#define GENOM_SIZE 64
#define GENOM_NUM 10
#define MUTATION_RATE 5
__device__ unsigned int rand(unsigned int* seeds){
seeds[threadIdx.x] = seeds[threadIdx.x] * 0x97531 + 0x13579;
@macrat
macrat / no_if_loop.c
Last active November 26, 2015 12:52
forもwhileもifもswitchも、分岐する文を全て使わずにループを書きたかった。
#include <stdio.h>
void void_func(int v){
}
void loop(int i){
printf("hello, world! %d\n", i);
((void (*)(int))((long long)loop * (i<9) + (long long)void_func * (i>=9)))(i + 1);
}
@macrat
macrat / calc.cs
Last active November 27, 2015 15:36
C#勉強会で出たお題の回答。二つ目は計算とスタックの管理を分離するってのを試してみたやつ。
using System;
using System.Collections.Generic;
class Calc{
static double Run(string[] ops, int idx){
Dictionary<string, Func<double, double, double>> funcs = new Dictionary<string, Func<double, double, double>>(){
{"+", (l, r) => l + r},
{"-", (l, r) => l - r},
{"*", (l, r) => l * r},