June 2010 Archives

New Prime Minister Naoto Kan

| No Comments | No TrackBacks

In Japan, after a huge dispute around the U.S. military base on the southen land of Okinawa and money scandals, Mr. Naoto Kan has been elected from Democratic Party of Japan (DPJ) as a new prime minister of Japan.

An interesting fact is that he graduated Tokyo Institute of Technology on 1970, not surprisingly which has little politicians in Japan. Unlike many prime ministors, he is not a "second generation," either. However, he is considered as one of the most experienced politicians in DPJ.

In the BBC news, he is seen as a strait-talker, especially for standing up to the bureaucracy. In 1990s, he exposed a scandal involving HIV-tainted blood products, which had infected the HIV with many people in Japan.

His speech emphasised the neccesity of the economic improvement and the governmnet's fincancial reformation, implying the raise of the consumption tax, or VAT. In this sense, he seems to be more realistic than his predecessor, Mr. Yukio Hatoyama, as Mr. Kan has served the finance ministry from January. IMD, Swiss business institute, estimated that Japan has the worst dept in the developed countries, would take until 2084 to clear.

Only one soundness in finance may be the VAT rate of 5%, which is one of the lowest among these countries.

He is facing many issues for the first place, and a mid-term election is waiting for the new government.


7行プログラミング

| No Comments | No TrackBacks

2チャンネルで「七行プログラミング」というものが2001年ごろから行われているそうです。 もともと、DVDの暗号を解読するためのプログラムのなかに、perlで7行で記述されたものがあったのが発端だそうです。

8ビットパソコン時代を知っている人なら、1行プログラムや1画面(40 x 25や80 x 25)に収まるプログラムがあったことを覚えている人もいることでしょう。 短いコードで如何に効率的に処理をするのか、パズルのような楽しみがあります。

そんなわけで、私もトライしてみました。 別に7行にこだわることはないのですが、せっかく7行プログラミングというものがあるので、それに準じて7行に詰め込んでみます。

#include <stdio.h>
int main(int c,char **v){int p=0,h=0,q,l,z=0;FILE *f=fopen(v[1],"wb");for(c=0;c
<44;c++)putc("RIFF0000WAVEfmt \x10\0\0\0\x01\0\x01\0D\xa2\0\0D\xa2\0\0\x01\0\b\
0data0000"[c],f);do{scanf("%d %d",&q,&l);for(c=0;c<l&&q>=0;c++){h+=q;if(h>=2756
){h-=2756;p++;}putc(("@LV]_]VL@4*#!#*4"[p&15]-32)*4,f);z++;}}while(q>=0);fseek(
f,40,0);fwrite(&z,1,4,f);z+=28;fseek(f,4,0);fwrite(&z,1,4,f);fclose(f);}

ブラウザや設定によって表示が等幅でないかもしれませんが、一行79文字で改行してあります。 文字列の途中に改行を入れているところがありますが、実際は連結します。

これは、DDS (Direct Digital Synthesis)方式のサイン波ジェネレータです。 モノフォニックですが、入力に基づいて44100Hz, モノラルのメロディをwav形式で出力します。

コンパイルは以下のとおりです(ソースファイルをwav.cと仮定)。

% cc wav.c

入力は次の形式で与えます。

  • 周波数(Hz)と長さ(44100=1秒)をスペースで区切って入力
  • 周波数を0にすると休符
  • 周波数を-1(マイナスの値)にすると終了

例えばこんな感じ。

% a.exe a.wav
440 22050
0 11025
880 11025
-1 -1
%

サンプルとして、Ysから一曲、次のようにすると作成します。

% a.exe a.wav < ys.txt 

調が違う(もしかしたらメロディも)のはご愛嬌。 サイズの関係で波形をケチっているので少々エイリアスの発生がありますが、雰囲気は伝わるのではないかと思います。

お持ち帰りダウンロードはこちらからどうぞ。 実行形式はWindowsのcygwinでコンパイルしてありますので、cygwinがインストールされている必要があります。

(5 Jun. 2010追記) ファイルの内容が間違っていたのを修正しました。

includeがある関係で1行目がスッカスカです。 また、実際には6行で済んでいるため、7行目がまだあります。 お題としては、次のようなことが考えられます。

  • ポリフォニック(複数音同時発音)にする
  • 音にエンベロープをつける
  • MML (Music Macro Language)の入力を可能にする

どなたかチャレンジしてみませんか?