複利計算
30分プログラム、その538。anarchy golf - Compound interest via http://gauc.no-ip.org/awk-users-jp/blis.cgi/DoukakuAWK_018。
素直にforでループすればいいのに、無理に再帰で書いてしまった。どうせ、出力するときにfor使ってるのにね。
あと久しぶりにfor(each)修飾子と$_を使った。Perlといえば、$_ですよね。
使い方
$ perl compound.pl 20:100:5 100 105 110 115 120 126 132 138 144 151 158 165 173 181 190 199 208 218 228 239 250
ソースコード
#! /usr/bin/perl # -*- mode:perl; coding:utf-8 -*- # # compound.pl - # # Copyright(C) 2009 by mzp # Author: MIZUNO Hiroki / mzpppp at gmail dot com # http://howdyworld.org # # Timestamp: 2009/03/04 21:17:21 # # This program is free software; you can redistribute it and/or # modify it under MIT Lincence. # use strict; use warnings; use Data::Dumper; use integer; my ($times,$init,$percent) = split ':',$ARGV[0]; sub compound($$$) { my ($n,$value,$percent) = @_; if($n == 0) { $value; } else { ($value,&compound($n-1,$value + $value * $percent/100,$percent)); } } print "$_\n" for( compound($times,$init,$percent) );