4clojure 题解 Reverse Interleave

作者: admin 日期: 2017-12-29 17:22:33 人气: - 评论: 0

按照数值给一个序列交错分组


Write a function which reverses the interleave process into x number of subsequences.

test not run
(= (__ [1 2 3 4 5 6] 2) '((1 3 5) (2 4 6)))
test not run
(= (__ (range 9) 3) '((0 3 6) (1 4 7) (2 5 8)))
test not run
(= (__ (range 10) 5) '((0 5) (1 6) (2 7) (3 8) (4 9)))









使用了clojure中的group-by方法


(fn [coll x]
(->
   (group-by #(rem % x) coll)
(seq)
(map second)))


相关内容

发表评论
更多 网友评论0 条评论)
暂无评论

Copyright © 2012-2014 我的代码板 Inc. 保留所有权利。

页面耗时0.0197秒, 内存占用1.83 MB, 访问数据库13次

闽ICP备15009223号-1