Skip to content

Instantly share code, notes, and snippets.

View gist:19cc68d17ba375525364
using System;
using System.Collections;
using System.Text.RegularExpressions;
class Word : IComparable
{
public string word;
public int count;
View gist:a24448abb150c1f90d99
import collections
import re
text = """I'm sorry but I don't want to be an Emperor. That's not my business.
I don't want to rule or conquer anyone.
I should like to help everyone if possible, Jew, gentile, black man, white.
We all want to help one another, human beings are like that.
We all want to live by each other's happiness, not by each other's misery. We don't want to hate and despise one another.
In this world there is room for everyone and the earth is rich and can provide for everyone.
@macrat
macrat / gist:a2398d15f049fe288ce1
Created May 14, 2015
pythonでもやっぱり一行でじゃんけんをしようかと思ったのでした。EOFErrorには勝てなかったよ。
View gist:a2398d15f049fe288ce1
(lambda hands : (lambda usr, cpu: print('usr: {0}\ncpu: {1}\n{2}'.format(hands[int(usr)], hands[cpu], ('drow :-)', 'lose...', 'your win!!')[(3+int(usr)-cpu)%3]) if usr.isdigit() and 0 <= int(usr) <= 2 else 'incorrect input!'))(input('jan! ken!! game!!!\nplease your hand(0:{0}, 1:{1}, 2:{2}):'.format(*hands)), __import__('random').randint(0, 2)))(('guu', 'choki', 'paa'))
@macrat
macrat / gist:0654a24322f09e946a09
Last active Aug 29, 2015
一行でじゃんけんをしようかと、そんなことを思ったのでした。
View gist:0654a24322f09e946a09
#include <stdio.h>
int main(int usr, unsigned int cpu, char** hands)
{
return printf((0 <= usr && usr <= 2) ? "you: %s\ncpu: %s\n%s\n" : "incorrect input!\n", hands[usr], hands[cpu%3], ((char*[]){"drow :-)", "lose...", "your! win!!!"})[(3+usr-cpu%3)%3], (usr=-1)&&scanf("%d", &usr), printf("jan! ken!! game!!!\nplease your hand(0:%s 1:%s 2:%s):", hands[0]="guu", hands[1]="choki", hands[2]="paa")) == 17;
}
@macrat
macrat / gist:78e7757aec30e4ac4b04
Created May 15, 2015
昨日の続き、今度は一行で階乗の計算。素直過ぎてつまらない。
View gist:78e7757aec30e4ac4b04
#include <stdio.h>
int main(int argc, char** argv)
{
return argc == 2 ? printf("%d\n", main(-atoi(argv[1]), argv))==0 : (argc < -1 ? -argc*main(argc+1, argv) : -argc);
}
@macrat
macrat / gist:931a74578bcf5cc8efff
Created May 26, 2015
二分探索を実装してみましょうかという感じ。バグがありそうな気がしている。
View gist:931a74578bcf5cc8efff
#include <stdio.h>
void showList(char** list, size_t length)
{
printf("%d: ", length);
for(int i=0; i<length; i++)
printf("%s, ", list[i]);
printf("\npivot: %s\n\n", list[length/2]);
}
@macrat
macrat / gist:dac3605c75297da44cac
Last active Aug 29, 2015
賭けじゃんけん。猛烈につまらないコードになった。
View gist:dac3605c75297da44cac
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
#define FUNDS_INITIAL 50000
#define MINIMAL_PREMIUM 100
const char* HANDS[] = {"guu", "choki", "paa"};
@macrat
macrat / gist:81eccba1fa93884636b1
Last active Aug 29, 2015
やったーC言語でクラス書けたよー! ・・・二度と書くもんか。
View gist:81eccba1fa93884636b1
#include <stdio.h>
#include <stdlib.h>
typedef struct stMY_CLASS{
char *name;
char* (*GetName)(struct stMY_CLASS*);
void (*SetName)(struct stMY_CLASS*, char*);
}MyClass;
@macrat
macrat / gist:0bcb58ba02d9eb24a445
Created Jun 18, 2015
C言語なんか真面目に触っちゃいけないぞ。というお話をしていた。
View gist:0bcb58ba02d9eb24a445
#include <stdio.h>
struct stTAMA_CHARS {
char t;
char a;
char m;
char A;
};
@macrat
macrat / gist:fe70b2af058260f663ef
Created Jun 24, 2015
webサーバ(笑)。どんなアクセスをしてもhello,worldしか返さない。
View gist:fe70b2af058260f663ef
import socket
ssock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssock.bind(('localhost', 8080))
ssock.listen(1)
message = 'hello, world!\n'
dat = '''HTTP/1.1 200 OK