ときどきの雑記帖'

最新ページへのリンク
目次ページへのリンク

一つ前へ 2013年2月(中旬)
一つ後へ 2013年3月(上旬)

ホームへ

2013年02月28日

■_

Think Simple―アップルを生みだす熱狂的哲学
とりあえず読了。 なんというか「スティーブ(・ジョブズ)はすごかったよね」というお話になっちゃうんだろうけども。 どうもこうなにか引っかかるものが残るのよね。 うまく言語化できないんだけど。 あ、そうそう。第8章だったかにNeXTの名前の由来というかそれに決まった経緯ってのが載ってて、 それが一番印象に残ったかなあ。

■_

■_ Ada

What's The Difference: Ada Then and Now | Dev Tools content from Electronic Design

What's The Difference: Ada Then and Now | Dev Tools content from Electronic Design

The International Organization for Standardization recently approved the latest revision of Ada,
known as Ada 2012, close to 30 years after the very first version. The language’s evolution shows
how Ada has accounted for major software technology developments of the past several decades while
retaining the original aims and flavor of its initial design.

Table Of Contents

    Ada 83: A Portable, Modern High-Order Language
    Ada 95: Here Come The Objects, And More
    Ada 2005: The Joy Of Interfaces
    Ada 2012: Contract-Based Programming For Today’s Software Challenges

以下略

Why BIND 10 is written in C++ and Python : programming

■_ BIND 10

BIND 10では記述に使ったプログラミング言語を変えたというお話

Programming Languages for BIND 10 | Blogs by Internet Systems Consortium

27 Feb 2013
Programming Languages for BIND 10

This blog post comes in response to a question that arrived via Twitter:

    @nodakai: WHY BIND10 had to be written in C++?? I think supporters of managed languages have much
    to learn from this unfortunate incident

(略)

The first question is of course, “Why not C?” Some answers are:

    String manipulation in C is a tedious chore
    C lacks good memory management
    Error handling is optional and cumbersome
    Encapsulation and other object-oriented features must be emulated

(略)
The approach that we ended up choosing in the end is to use a mix of two languages:

    Python
    Whenever possible, we use Python. Python is a very popular language, usually the most popular of
    the scripting languages on most surveys (possibly excepting PHP). It has all of the features that
    we were looking for… except performance.

    C++
    When necessary, we use C++.

    C++ is also a very popular language, and also has all of the features we are looking for.
    However, C++ is by no means an easy language to work with, so the idea is that we will avoid its
    complexity when possible.

可能な限り Python で。ですか。へー。

■_ C

こっちは C の話 Why Code in C Anymore? | Dr Dobb's Why code in C anymore? : programming

■_

二月が逃げた

2013年02月27日

■_

緑の山手線

半額セール Data Analysis, Data Mining and Data Management - O'Reilly Media This deal expires February 28, 2013 at 11:59pm PT and cannot be combined with other offers. Offer does not apply to Print, or "Print & Ebook" bundle pricing. なにかあるかな

名著20 『モンテ・クリスト伯』:100分 de 名著 実はまだ読んだことがなかった。 長そうだけど読んでみようかなあ。

Redline – JVMで動作するSmalltalk処理系開発者が開発資金を募集中 | #JVMood これ見てもうすぐ締切だったのを思い出して慌てて$50ほど寄付。 しまった。ステッカーの送料分色をつけておくんだった。

■_

■_

スライド見た。 おすすめ。 Static vs. Dynamic Languages

Agenda

. Why you should care
. Dynamic languages
. Definitions
. Stereotypes
. Myths
. Other features
. When and how to move
Static Language Stereotypes

. Compiled to machine code => fast execution
. Variables declared - to allocate registers, stack, heap
. Variables typed - to determine which machine instructions
. Types checked at compile-time
. Catch some errors early
. Increase run-time speed
. Facilitate optimization
. Remove the need for run-time type checking

Dynamic Language Stereotypes

Negative stereotypes:
. Interpreted => slower
. Type-checking at run-time (not un-typed!)
. Type errors are caught later
. Run-time checks => slower
. More risky?

We'll come back to these

■_

スライド見た。その2。 なかなか面白そう? Grace: An Open-source Educational OO Language スライドからいくつか

Principles

・Simple programs should be simple
・Understandable semantic model
・Be a general-purpose language
・Optional types
・Support different teaching orders
var fib := 1
var fibprev := 1
for (3..7) do {i ->
    def tmp = fibprev
    fibprev := fib
    fib := fib + tmp
}
print "7th Fibonacci number: {fib}"

def FibonacciCalculator = object {
    var current := 1
    var previous := 1
    var upTo := 1
    method next {
      upTo := upTo + 1
      current := current + previous
      previous := current .. previous
      return current
    }
    method printNext {
      print "{upTo+1}th Fibonacci number: {next}"
    }
}

Control structures as methods

method if(c : Boolean) then (t : Block) else (f : Block) {
  c. ifTrue (t)else(f)
}

method while(c : Block) do(a : Block) {
  c.apply. ifTrue {
    a.apply
    while (c) do (a)
  }
}
Implementation
・Written in Grace
・Supports almost all of the dynamic language
・Static typechecking present but limited

Compiler source code:
https://github.com/mwh/minigrace
Tarballs:
http://ecs.vuw.ac.nz/~mwh/minigrace/
Client-side web front-end:
http://ecs.vuw.ac.nz/~mwh/minigrace/js/

■_ いてれーと

なんか似たようなのが Iterables, Iterators and Generators: Part 1 - excess.org Iterables, Iterators and Generators: Part 2 - excess.org Iteration Inside and Out – journal.stuffwithstuff.com Iteration Inside and Out, Part 2 – journal.stuffwithstuff.com

■_

Attendre et espérer !

2013年02月26日

■_

最上位割り込みでこの本が Think Simple―アップルを生みだす熱狂的哲学

今日はちといろいろあって以下略

■_ ベストなプログラマーとは

Hacker Newsは割と伸びてるんだけどredditはそうでもないですね。 なんでだろ。 The best programmers are the quickest to Google : programming The best programmers are the quickest to Google | Hacker News

で、どういうこと言ってんのよ。というと

Framebase • The best programmers are the quickest to Google

(略)

If you need to implement something in code and it's not cutting edge technology, Google it first.
If someone else hasn't already done it yet, you're either Googling it wrong or way off in what you're
trying to accomplish. If you've given it your best effort, find someone to ask for help.

The best programmers I know understand how to architect and build large projects piece by piece.
They can focus on the macro because don't get hung up in the pieces. They know how to use Google to
find solutions fast. DRY.

楽しむため(fun) や練習 (practice) のためでないのなら時間をかけて 自分で組み上げるこたないよ。とっととぐぐって誰かの成果を見つけちゃいな。 ってな話みたいですね(例によって超訳)。

■_

■_

数日こんな感じかもしれません。

2013年02月25日

■_

めぐりあい宇宙編のドズルの台詞をもじって 「戦いは『カネ』だよ兄貴!」 と言いたい今日この頃。

戦いは数だよ兄貴!とは - はてなキーワード

■_

2話のヤマト起動のシーンの話からこれに

【改悪】宇宙戦艦ヤマト2199のここがマジ赦せん!9

34 名無しさん@お腹いっぱい。 [sage] 2013/02/25(月) 20:21:42.75 ID:jZsG8dko0 Be:
    シリアル通信がうまくいかないってんで
    受信されたデータをホワイトボードに書いたら極性が逆だったとか
    データがときどき取り込めなくなるというので調べたら
    電源ラインが弱くて負荷最大のとき不安定になってたとか
    相互接続試験したら相手とまったく通信ができなくて
    プロトコルの話をしたら向こうがとんでもない勘違いをしてたとか
    現場ってのはわけわからんことが平気で起きるところだ

    一発で動くのはフィクションだけだよ 

■_ スパゲッティ

1993/Meertens: "The design of elegant languages" * Limitations of the human mind * The programmer's task * On elegance * From ALGOL 60 to ALGOL 68 => "Van Wijngaarden's insight was that the required generalization of the syntax rules could be obtained by introducing parametrized grammar rules" (PDF) : programming から


Suppose we have to write a program for some task T, which is too complex to be expressed directly as
a basic step. However, whenever a certain condition C is satisfied, the task T can be reduced to the
simpler task TO, whereas otherwise it can be simplified to Ti. So, assuming we have programs for TO
and Ti. we can now give one for T. In FORTRAN such as it was when ALGOL 60 was being designed,
conditional execution was achieved by using "conditional jumps" in the program. This language
construct was modelled rather straightforwardly after the same low-level machine-code instruction on
the IBM 704. Using ALGOL 60 syntax style, we get then :

  Li:
  L2:
  if not C then goto Li;
  TO;
  goto L2;
  T1 ;

If TO and Ti are still too complex aid are likewise decor lposed into subtasks, and so on, we arrive
at the third step at the following: 
Conference on the History of ALGOL 68

        if not C then goto L1;
        if not C0 then goto L01;
        if not C00 then goto L001;
        TO00;
        goto L2;
  L001: T001;
        goto L2;
  L01:  if not C01 then goto L011;
        T010 ;
        goto L2;
  L011: T011;
        goto L2;
  L1:   if not C1 then goto L111 ;
        if not C10 then goto L101;
        T100;
        goto L2;
  L101: T101;
        goto L2;
  L11:  if not C11 then goto L111;
        T110;
        goto L2;
  L111: T111;
  L2:

The result looks like spaghetti but is rather more unpalatable. It is far from easy to see from this
text under what conditions exactly T101, for example, will be executed. It is, of course, not
accidental that this resembles compiled code. I t is compiled code: handcompiled from the abstract
idea into to the limited constructs of a programming language.

見事なスパゲッティでした。

■_

2013年02月24日

■_

おめでとうございます(関係者の方々お疲れさまでした)。 自前ビルドしなくなって久しいので、PC新しくしたらまた環境整えていじりたいなあ (しかし今はmrubyの方が狙い目?) Ruby 2.0.0-p0 is released Ruby 2.0.0 Released | Hacker News Ruby 2.0.0 : programming

「MIT白熱教室」
最終回でした。最後の語りがちとぐさっと。 書籍版もそろそろ買って読むかなあ。 オビがないと書影の印象がだいぶ違いますねw
これが物理学だ! マサチューセッツ工科大学「感動」講義
これが物理学だ! マサチューセッツ工科大学「感動」講義

空飛ぶ Python。 書店で見かけたのでざっと眺めたけどとりあえず買わなくて良いかなあ。 出来が悪いということではなく、自分が求めているような内容は載っていない印象があったからです。 だいぶ本を買うハードルが高くなっているので。はい。 書評書けと送りつけられることもないでしょうし。

読むキューに割り込みで入ってきた本
ぼくとビル・ゲイツとマイクロソフト アイデア・マンの軌跡と夢
ぼくとビル・ゲイツとマイクロソフト アイデア・マンの軌跡と夢

原著からして出たのを知らなかったのだけど(書いている、出版されるというのは知っていた)、 翻訳本が出てたとは。とはいえAmazonさんのページの記述によれば 2/19 発売なので 出たばかりですね。 区別がつかないけど順にハードカバー、ペーパーバック、Kindle版で、 ハードカバーが2011年4月の発売らしいですね。なんで気がつかなかったんだ。 Idea Man: A Memoir by the Cofounder of Microsoft Idea Man: A Memoir by the Cofounder of Microsoft Idea Man: A Memoir by the Cofounder of Microsoft

まだ第4章辺りまでしか読んでないんで感想等は書きませんが (artonさんの本もまだ半分くらいなので)、 15ページ、4004の話が出てきたところで 「フェデリコ・ファギン」と書かれてたのがちょっと気になった。 人名だしイタリア系の人だしどう表記するのが実際の発音に近いのかわからないけど 「フェデリコ・ファジン」じゃまずかったんだろか フェデリコ・ファジン - Wikipedia Federico Faggin - Wikipedia

↑を買った書店でこのシリーズを置いている棚を見かけたんですが、 200冊までいったんですねえ。だいぶ「品切重版未定」が目立つのが残念だけど 岩波科学ライブラリー

■_ D is for

やはり同様の考えをする人がいた :)

とはいえ「デはディジタルのデ」も直球過ぎるんでもう一ひねり欲しいわねえ。

■_ どれがいい?

Tour of best modern Lisp implementations? : lisp

Tour of best modern Lisp implementations? : lisp

I know of Common Lisps (ECL, CLISP, CCL, AllegroCL...), Schemes (Chicken, Racket, Kawa...), and
other strange variants like EmacsLisp, Clojure, newLISP and Nu, but I'm sure there's more out there.
What are your favorite choices of Lisp implementations, and how do they help you accomplish your goals?


Here's Andy Wingo's (GNU Guile hacker) guide to Scheme implementations. I'm constantly torn whether
to use clojure or Racket for small toy projects, but I end up using clojure because of some Java
library. I'd say that both are extremely practical and modern Lisps.

I have used EmacsLisp, it's ridiculously easy to get started (if you know your way around emacs), but
haven't done anything practical with it.


CCL. It supports threads well enough on Windows to run Hunchentoot.


Clojure for doing quick or serious stuff for clients, CL when I need something that 
runs fast or when I need to quickly setup some project (thanks to awesome quicklisp) 
and tinyscheme when I need to add scripting ability.

Other than that, I also prefer newLISP for making CGI-enabled sites on shared hosts, 
where you can't be assured what language/version/package will be installed. Single 
binary with huge number of functions and features saved me a couple of times.


how do you use newLISP on shared hosts, I imagine that you require a hosting provider 
that gives you a shell and the ability to bind your own ports? is that common? or am I 
misunderstanding your usage


Yes, this implies shared hosts with shell support where I simply uploaded newlisp 
binary, since the binary depends on small number of shared libraries.

Scripts are running as plain cgi scripts (started by web server) and there is no need 
for using additional server (contrary to CL). newLISP starts up really fast, so using 
cgi makes almost zero overhead. The best of all, scripts has threading support (thanks 
to 'spawn') so I'm able to do a bunch of stuff in a single run.


so you would say that you follow the idea behind the article here and compile/ship 
newLISP binaries/libraries? btw, you add functionality, compile, and distribute a new 
binary? or did you mean that newLISP comes with enough functionality built in that its 
feature complete for your needs, or that your scripts reference libraries that you 
ship alongside the newLISP binary?


    or did you mean that newLISP comes with enough functionality built in that its feature complete for your needs

Yup, this is what I tried to say. Also for things not present, there is super easy FFI 
for accessing external libraries.

    so you would say that you follow the idea behind the article here

Also true, as CGI is quite simple.


Thank you very much, I've been wondering about such things for quite a while now.


I use CL (CCL and SBCL) for most things. I was big into Clojure in a previous job 
where we were in a strict Java ecosystem (and ABCL wasn't as mature as it is now.)

I haven't looked at the others, and haven't used Scheme in anger since I was in 
college many many moons ago.

    and haven't used Scheme in anger since

:( I rather like Scheme, I think it's much more consistent than Common Lisp. Chicken Scheme in
particular is wonderfully practical, shipping with both an interpreter and compiler.


GNU Guile is great for an embedded Scheme.


GOO. I haven't used it for anything useful: the implementation is clunky, with very 
verbose backtraces and useless error messages. But the language is very beautiful. It 
would make for a perfect kernel language for Dylan, or another CLOSy Lisp.

http://www.eecs.berkeley.edu/~jrb/goo/

紹介されてたこれは知らなかった。 an opinionated guide to scheme implementations -- wingolog

一度作りたいとは思ってるんですよ。ええ。

■_ 在宅勤務

ううむ、こんな話になってたのね。 なにがどうなってこうなったんだろう。 Killing Remote Workers; Yahoo!’s backwards move — I.M.H.O. — Medium

■_ 電流爆破

つい最近も行われて、そのときも特許云々とか書かれていたような覚えがあるんですが 時期的に期限切れてるんじゃあなかろうかと思って (それと、特許の請求項やらがどうなってるのか気になったw)うぃきぺを見ましたら

デスマッチ - Wikipedia

電流爆破デスマッチ [編集]

大仁田厚がFMWで開発したスタイルの試合で、有刺鉄線に電流を流し、なおかつ小型爆弾を設置する。電流は
ダメージを与えることが目的ではなく、接触を検知し小型爆弾を爆発させるためのものである。視覚面と音響
面でインパクトが強いため、1990年代には盛んに行われた。初めての試合は大仁田とターザン後藤が汐留で対
戦したノーロープ有刺鉄線電流爆破マッチ。

(略)

IWA・JAPAN、新日本プロレス、SPWFなどの団体でも開催されている。一時期、大仁田が電流爆破デスマッチの
リングを含む装備に関して、特許を申請して認められたため、大仁田の許可無しでは行えないといわれたが、
実際には認められていなかったので、大仁田が関係しない団体でも行うことができた。

大仁田が第一線から退いていたこともあり2003年9月を最後に電流爆破デスマッチは行われなくなったが、2012
年8月26日に大仁田対曙で「ノーロープ有刺鉄線バリケードマットダブルヘルメガトン電流爆破デスマッチ」と
称して9年ぶりに復活した。

あ、8月だったか。 にしても、出願はしたにせよ取得はできなかったのね。 公開特許公報に載ってるかな。

■_

新聞広告で見かけて気になった本。と、Amazonさんで調べたら一緒に引っかかった本。 Amazon.co.jp: 食糧の帝国――食物が決定づけた文明の勃興と崩壊 (ヒストリカル・スタディーズ): エヴァン・D・G・フレイザー, アンドリュー・リマス, 藤井美佐子: 本 Amazon.co.jp: ローマ帝国の食糧供給と政治―共和政から帝政へ: 宮嵜 麻子: 本

■_ めも

TMTに埋もれていたものから。

で、これを見ると Floating-Point Formats

Floating-Point Formats

Other computers, such as the PDP-11, and its successor, the VAX, dealt with the wastefulness of
having the first bit of the mantissa (almost) always one by omitting that bit from the
representation of a number. The number zero was still represented by a zero mantissa combined with
the lowest possible exponent value; thus, this exponent value had to be given the additional meaning
that the hidden one bit was not present. The diagram above shows only one of the formats used with
the PDP-11, although in single precision it was called the F format, and in double precision, the D
format. An early sofware format, belonging to Group II, also existed; it involved a 16-bit two's
complement exponent followed by a 32-bit two's complement mantissa; unlike H format, it did not have
a hidden first bit, and the sign of the mantissa was within the mantissa.

On the VAX and on the Alpha; other formats were used, including the G format, which had an exponent
field that was 11 bits in length, used in a 64-bit floating-point number, and which led to the
expanded range format for the PDP-10 which is shown above, and the H format, which had an exponent
field 15 bits in length, and which was used in a 128-bit floating-point number; these formats are
also shown above. Note that the hidden first bit was retained even in the 128-bit format, unlike the
case for IEEE-754.

なるほど。 リンクを上に辿っていったら全体も面白そう。 How Does A Computer Work?

■_

【タコには】横山信義総合スレ27【原爆だ!】 [chaika]

903 名無し三等兵 [sage] 2013/02/23(土) 22:25:52.22 ID:??? Be:
    ハチハチ勇進編新刊一回読了

    ふと入ったブクオフで
    八八艦隊物語1~4巻が揃ってたので購入

    古典に親しみます 

八八艦隊物語は全五巻だったような…。 文庫版は違ったんだっけか?

■_

2013年02月23日

■_

土曜日の朝に↑を見て(ツイート時刻との差はまあごにょごにょ)、 一気に行く気が失せてしまったので本日分は実質上お休みです。

なぜと問われても答えようがないのですが(多分に感情的なものだから)、 キャンセル待ちとかしてた人がいたらごめんなさい。

2013年02月22日

■_

誕生日なので私の訳書・監訳書を献本します - 角谷HTML化計画(2013-02-19) JaSSTあったじゃないですか。 あれにわたしのいる部署(と関係する部署)から何人か行ってたのですが、 先日その報告会というのがありました。 これこれこういう興味深い発表がありましたとかなんとか。 んで、発表者の一人が「アジャイル・サムライ」に言及したのですけど 「今まで読んでなかったのですが有名な本らしいので立ち読みしてみます」 的なことを言ったのですね。 よっぽどかくたにさんは知り合いなので是非、買って読めとツッコミを入れようと思ったのですが 脳内で展開されるその後のやり取りに不安を感じて黙っていたのでした (深読みのしすぎとも言う)。

最終回ですねえ >MIT白熱教室 MIT Department of Physics Walter Lewin - Wikipedia, the free encyclopedia

■_

■_ 観る

Socio-PLT: Principles for Programming Language Adoption Leo A. Meyerovich explains how social adoption patterns can help language designers make new languages that are inherently attractive and desirable by developers.

■_ GC

Lua で、書き方によってGCに対する影響が違うとか bitsquid: development blog: Garbage Collection and Memory Allocation Sizes

bitsquid: development blog: Garbage Collection and Memory Allocation Sizes

Let's look at a simple example in Lua. Say we want to write a class for managing bullets. In the
non-data-oriented solution, we allocate each bullet as a separate object:

  function Bullet:update(dt)
      self.position = self.position + self.velocity * dt
  end

  function Bullets:update(dt)
      for i,bullet in ipairs(self.bullets) do
          bullet:update(dt)
      end
  end

In the data-oriented solution, we instead use two big arrays to store the position and velocity of
all the bullets:

  function Bullets:update(dt)
      for i=1,#self.pos do
          self.pos[i] = self.pos[i] + dt * self.vel[i]
      end
  end

どっちがどうなのかは元記事を見てのお楽しみ。

■_ floating point quirks

う、もう一か月前のネタかこれ(TMTのタブから拾い出してきた)。 まあ、知ってる人は知っているお話です。はい。 Floating point quirks | Sanity Phailed.me

Floating point quirks: how summing a series backwards gave 4 orders of magnitude more accuracy : programming

Floating point quirks: how summing a series backwards gave 4 orders of magnitude more accuracy : programming

You probably want to use compensated summation when summing floating point values.
or how floating point trades accuracy for speed.

It's not a tradeoff: accuracy is impossible.

Edit: For those who have asked, What Every Computer Scientist Should Know About Floating-Point
Arithmetic is a great primer.

The TL;DR is that you can't accurately represent even the rationals with a finite number of bits as
floating point numbers. This includes some rationals that have a terminating representation in
decimal, e.g. 0.1, because the computer represents them in binary and their binary representation
does not terminate (in this case it's 0.00011001100110011...).

Also, Zarutian is correct in saying that floating point numbers trade accuracy for speed. The
rationals can be represented perfectly (up to memory limitations) but math with these representations
is significantly slower. In some cases, however, accuracy is actually impossible. I will leave my
original comment to maintain the integrity of the thread.

そういや、「What Every Computer Scientist Should Know About Floating-Point Arithmetic」 の日本語訳って今でも読めるのでしたっけ? 以前は sun のサイトのどこかにあったように覚えているのですが。

数値計算の基礎―解法と誤差
数値計算の基礎―解法と誤差

2013年02月21日

■_

今週の土曜日はOSCやらもあったのねえ。

■_

とは言え、マイクロプロセッサの右シフトも算術シフトと論理シフトがあり、 左シフトではその二つに違いはないというものだったりするので その辺の非対称性は気にならなかったのだった。

■_

こんな本がががが(実は某所で見かけたのだった。帯にあの人が推薦文を書いてました)

調べてみるとなかなかすごそう ジョージ・ダイソン、最新の大著、「チューリングの大聖堂―デジタル宇宙はいかに建設されたか」を語る 今年最大のテクノロジー関連の書籍かもしれない。その本はGeorge DysonのTuring’s Cathedral: The Origins of the Digital Universe〔「チューリングの大聖堂―デジタル宇宙はいかに建設されたか」〕 だ。 ジョージ・ダイソン『チューリングの大聖堂』が今月発売 - YAMDAS現更新履歴 昨年「邦訳の刊行が期待される洋書を紹介しまくることにする(2012年版)」で紹介したジョージ・ダイソンの『Turing's Cathedral: The Origins of the Digital Universe』の邦訳が今月出る。 昨年 TechCrunch に本の紹介とインタビュー動画が掲載されているが、Wall Street Journal が選ぶ2012年のビジネス書ベスト選にも選ばれているし、期待大である。

ただなあ…分厚いんだよなあこれ。

チューリングの大聖堂: コンピュータの創造とデジタル世界の到来
チューリングの大聖堂: コンピュータの創造とデジタル世界の到来

■_

エントロピー符号 〜 横へな 2013.3.1 の参考問題 昨日の、PowerShellでやってみた。 見ての通り完全なる力業です(語頭符号万歳)。

filter tobin {
    $v = $_
    $v = $v -replace "0","0000"
    $v = $v -replace "1","1000"
    $v = $v -replace "2","0100"
    $v = $v -replace "3","1100"
    $v = $v -replace "4","0010"
    $v = $v -replace "5","1010"
    $v = $v -replace "6","0110"
    $v = $v -replace "7","1110"
    $v = $v -replace "8","0001"
    $v = $v -replace "9","1001"
    $v = $v -replace "a","0101"
    $v = $v -replace "b","1101"
    $v = $v -replace "c","0011"
    $v = $v -replace "d","1011"
    $v = $v -replace "e","0111"
    $v = $v -replace "f","1111"

    return($v)
}

$table = @{
    "000"="t";
    "0010"="s";
    "0011"="n";
    "0100"="i";
    "01010"="d";
    "0101101"="c";
    "010111"="l";
    "0110"="o";
    "0111"="a";
    "10"="e";
    "1100"="r";
    "1101"="h";
}

filter decode {
    $v = $_
    $len = 0
    $str = ""

    while ($true) {
        $cond = [regex]::match($v, "^111")
        if ($cond.success) { return($str + ":" + ($len + $cond.length)) }
        $m = [regex]::match($v, "^(000|0010|0011|0100|01010|0101101|010111|0110|0111|10|1100|1101)")
        if (-not $m.success) { return("*invalid*") }
        $len += $m.length
        $str += $table[$m.value]
        $v = $v.substring($m.length)
    }
}

正規表現のところも「最適化」すべきなんだろうけどパス。

PS C:\Users\kbk\work> Get-Content .\sampleinput.txt
16d9d4fbd
df
ad7
870dcb
880f63d
a57cbe56
36abef2
ad576cd8
3e2a3db4fb9
51aa3b4c2
ad5f1a07affe
4ab8a86d7afb0f
ac4b0b9faef
cafebabe
43e7
53e7
86cf
b6cf
0
c
d
e
babecafe
8d
ad
af
ab6e0
a4371
a4371
96e3
0dc71
2a9f51
a43fb2
ab6e75
a5dcfa
ca97
6822dcb
PS C:\Users\kbk\work> Get-Content .\sampleinput.txt|tobin
100001101011100110110010111111011011
10111111
010110111110
000111100000101100111101
0001000100001111011011001011
01011010111000111101011110100110
1100011001011101011111110100
01011011101011100110001110110001
11000111010001011100101111010010111111011001
101010000101010111001101001000110100
010110111010111110000101000011100101111111110111
00100101110100010101000101101011111001011111110100001111
01010011001011010000110110011111010101111111
00110101111101111101010111010111
0010110001111110
1010110001111110
0001011000111111
1101011000111111
0000
0011
1011
0111
11010101110101110011010111110111
00011011
01011011
01011111
01011101011001110000
01010010110011101000
01010010110011101000
1001011001111100
00001011001111101000
010001011001111110101000
010100101100111111010100
010111010110011111101010
010110101011001111110101
0011010110011110
0110000101000100101100111101
PS C:\Users\kbk\work> Get-Content .\sampleinput.txt|tobin|decode
ethanol:30
e:5
c:10
t:6
test:15
cat:17
roll:23
chant:25
rails:25
eeeteee:18
charset:31
slideshare:42
doctor:30
nlh:17
sra:15
eera:15
tera:16
hon:15
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*
*invalid*

それっぽく動いてるかな?

■_


一つ前へ 2013年2月(中旬)
一つ後へ 2013年3月(上旬)

ホームへ


リンクはご自由にどうぞ

メールの宛先はこちらkbk AT kt DOT rim DOT or DOT jp