Skip to content

Instantly share code, notes, and snippets.

@mnzk
mnzk / addr.sh
Created April 11, 2012 15:39
IPアドレス取得
#!/bin/sh
IP_ADDR1=`LANG=C /sbin/ifconfig \
| grep '^\s*inet addr' \
| grep -v '\b127\.0\.0\.1\b' \
| head -1 \
| awk '{print $2}' \
| cut -d: -f2`
echo "[$IP_ADDR1]"
@mnzk
mnzk / atcoder-q001-a.clj
Created April 15, 2012 01:54
atcoder-q001-a.clj
;; AtCoder 過去問 : 001-A 【センター採点】
;; http://arc001.contest.atcoder.jp/tasks/arc001_1
(defn q001-a*
[N cs]
(let [lafi (juxt last first)]
(->> cs
(reduce (fn [m c] (assoc m c (inc (m c))))
{\1 0 \2 0 \3 0 \4 0})
vals (into (sorted-set))
@mnzk
mnzk / atcoder-q001-b.clj
Created April 15, 2012 10:35
atcoder-q001-b.clj
;; AtCoder 過去問 : 001-B 【リモコン】
;; http://arc001.contest.atcoder.jp/tasks/arc001_2
(defn- q001-b*
[A B]
(letfn [(loop- [a b d acc xs]
(cond
(zero? d) acc
(empty? xs) (+ acc d)
:else (let [[x & xs] xs
@mnzk
mnzk / atcoder-q001-c.clj
Created April 17, 2012 15:40
atcoder-q001-c.clj
;; AtCoder 過去問 : 001-C 【パズルのお手伝】
;; http://arc001.contest.atcoder.jp/tasks/arc001_3
(use '[clojure.set :only (difference)])
(use '[clojure.math.combinatorics :only (permutations)])
(def ^{:private true} r8 (range 1 9))
(defn accession-pos-set
"座標 x y に置かれた Q の利き筋列挙"
@mnzk
mnzk / atcoder-q001-d.clj
Created April 18, 2012 12:51
atcoder-q001-d.clj
;; AtCoder 過去問 : 001-D 【レースゲーム】
;; http://arc001.contest.atcoder.jp/tasks/arc001_4
(defn- read-input
[]
(letfn [(read-num-pair
[] (->> (clojure.string/split (read-line) #"\s+")
(map #(Long/parseLong %))))
(read-num-pairs
[n] (repeatedly n read-num-pair))]
@mnzk
mnzk / ExPermutations.cs
Created April 23, 2012 13:13
ExPermutations.cs
using System;
using System.Linq;
using System.Collections.Generic;
static class Ex {
public static IEnumerable<IEnumerable<T>> RotationsL<T>(this IEnumerable<T> xs) {
for(int i = xs.Count(); i > 0; i--) {
yield return xs;
xs = xs.Concat(xs.Take(1)).Skip(1);
@mnzk
mnzk / ExPermutations2.cs
Created April 24, 2012 14:19
ExPermutations2.cs
// 辞書順で順列列挙
using System;
using System.Linq;
using System.Collections.Generic;
static class Ex {
private static IEnumerable<IEnumerable<T>[]> __MoveRtoL<T>(IEnumerable<T> e1, IEnumerable<T> e2) {
while(e2.Count() > 0) {
@mnzk
mnzk / sample_wpf.py
Created May 12, 2012 11:03
sample_wpf.py
from __future__ import print_function
import wpf
from System.Windows import Application
from System.Windows import Window
flip = lambda f, a: lambda b: f(b, a)
props = {'__init__' : flip(wpf.LoadComponent, 'w.xaml')}
win = type('', (Window,),props)()
@mnzk
mnzk / inv-fizzbuzz.clj
Created May 17, 2012 15:56
inv-fizzbuzz.clj
;; 逆 FizzBuzz
;; ------------------------------------------------
;; :dependencies [[org.clojure/clojure "1.4.0"]
;; [org.clojure/core.incubator "0.1.0"]
;; [org.clojure/math.numeric-tower "0.0.1"]]
;; -------------------------------------------------
(ns inv-fizzbuzz.core
(:use [clojure.core.incubator :only (-?>>)])
@mnzk
mnzk / evenodd.el
Created May 26, 2012 14:03
evenodd.el
(require 'cl)
(loop for x from 1 to 10000
do (insert (format "Case %d: a = %s\n"
x (if (zerop (% x 2)) "False" "True"))))