This file contains hidden or 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
;; 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)) |
This file contains hidden or 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
#!/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]" |
This file contains hidden or 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
;; こうじゃなくて | |
(and (not size) | |
(or width height)) (.setSize (or width 100) (or height 100)) | |
;; こうじゃないか? | |
(and (not size) | |
(not (and width height))) (.setSize (or width 100) (or height 100)) |
This file contains hidden or 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
(defmacro with-open-zipfile | |
[bindings & body] | |
(let [bindings# (->> bindings | |
(mapncat 2 (fn [v f] | |
`(~v (java.util.zip.ZipFile. ~f)))) | |
(into []))] | |
`(with-open ~bindings# ~@body))) | |
;; example |
This file contains hidden or 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
(defn mapn | |
([n f coll] | |
(->> (partition n coll) | |
(map (partial apply f)))) | |
([n m f coll] | |
(->> (partition n m coll) | |
(map (partial apply f)))) | |
([n m k f coll] | |
(->> (partition n m k coll) | |
(map (partial apply f))))) |
This file contains hidden or 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
#include <stdio.h> | |
typedef struct {unsigned short total, count; } s; | |
#define M_COUNT(x) (((s*)&x)->count) | |
#define M_TOTAL(x) (((s*)&x)->total) | |
int main(){ | |
int x = 0; | |
for(M_COUNT(x)=1; M_COUNT(x)<=100; ++M_COUNT(x)){ |
This file contains hidden or 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
;; seealso https://twitter.com/#!/mnzktw/status/155976688021405696 | |
(defn parse-args [args] | |
(->> (concat ["-f" nil] args) | |
(partition-by (partial = "-f") ) | |
(partition 2) | |
(map second) | |
((juxt (comp rest (partial map first)) | |
(partial mapcat rest))))) |
This file contains hidden or 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
// see also. https://gist.github.com/1430157 | |
open Microsoft.FSharp.Collections | |
let distanceOfSameValueElements xs = | |
let rec loop i dict xs = | |
let x = LazyList.head xs | |
match Map.tryFind x dict with | |
| None -> loop (i + 1) (Map.add x i dict) (LazyList.tail xs) | |
| Some j -> i - j |
This file contains hidden or 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
let distanceOfSameValueElements xs = | |
let rec loop i dict xs = | |
let x = LazyList.head xs | |
match Map.tryFind x dict with | |
| None -> loop (i + 1) (Map.add x i dict) (LazyList.tail xs) | |
| Some j -> i - j | |
loop 0 Map.empty (LazyList.ofSeq xs) |
This file contains hidden or 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
/// https://gist.github.com/1430157#file_euler26.fs の改良(高速化)版 | |
#light | |
let reccuringLength d = | |
let rec loop i dict n = | |
let r = n % d | |
match Map.tryFind r dict with | |
| Some j -> i - j | |
| None -> loop (i+1) (Map.add r i dict) (r * 10) | |
loop 0 Map.empty 1 |