5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「CodeIQ 2周年!」をLazyKで出力

Last updated at Posted at 2014-06-20
言語 CodeIQ 2周年おめでとうございます。
Brainf**k http://ideone.com/xwXeFp
https://github.com/cielavenir/codeiq_solutions/blob/master/q835/death2_bf.c
Intercal http://ideone.com/JbAqfF
http://qiita.com/cielavenir/items/0c9720f7df6d796a547a
Lazy K http://melpon.org/wandbox/permlink/kZSCbtHgnGnHxHeE
http://qiita.com/cielavenir/items/f4428c6a2aefbf8af532
Unlambda http://ideone.com/vQ1EQE
https://github.com/cielavenir/codeiq_solutions/blob/master/codeiq2nd_unlambda.rb
WhiteSpace http://ideone.com/VrQVsv
http://qiita.com/cielavenir/items/ebca62f3e689c049ac24

まず、以下のRubyプログラムでSchemeプログラムを生成します。

codeiq2nd_lazy.rb
#!/usr/bin/ruby
#coding:utf-8
def compile_codepoints(a)
	defined={0=>1,1=>1,2=>1,4=>1,256=>1}
	a.each{|e|
		n=e
		while n>0
			if n%2>0
				if !defined[n]
					puts "(lazy-def #{n} '(1+ #{n-1}))"
					defined[n]=1
				end
				n-=1
			end
			if !defined[n]
				puts "(lazy-def #{n} '(* 2 #{n/2}))"
				defined[n]=1
			end
			n/=2
		end
	}
end

STR="CodeIQ 2周年!\n"

puts <<EOM
(load "../lazier.scm")
(load "../prelude.scm")
EOM

compile_codepoints(STR.bytes.to_a)

puts <<EOM
(lazy-def '(ans in)
EOM

print "'"
STR.bytes.each{|e|print "(cons #{e} "}
print 'end-of-output'
STR.bytes.each{|e|print ")"}
puts

puts <<EOM
)

(print-as-unlambda (laze 'ans))
EOM

生成されたSchemeプログラムは以下のようになります。これを
https://github.com/msullivan/LazyK のegディレクトリに配置することで、goshなどでLazyKプログラムを生成します。
この際、lazier.scmのprint-as-unlambdaを"i"から"``skk"に変更しておくと吉です。

codeiq2nd_lazy.scm
(load "../lazier.scm")
(load "../prelude.scm")
(lazy-def 67 '(1+ 66))
(lazy-def 66 '(* 2 33))
(lazy-def 33 '(1+ 32))
(lazy-def 32 '(* 2 16))
(lazy-def 16 '(* 2 8))
(lazy-def 8 '(* 2 4))
(lazy-def 111 '(1+ 110))
(lazy-def 110 '(* 2 55))
(lazy-def 55 '(1+ 54))
(lazy-def 54 '(* 2 27))
(lazy-def 27 '(1+ 26))
(lazy-def 26 '(* 2 13))
(lazy-def 13 '(1+ 12))
(lazy-def 12 '(* 2 6))
(lazy-def 6 '(* 2 3))
(lazy-def 3 '(1+ 2))
(lazy-def 100 '(* 2 50))
(lazy-def 50 '(* 2 25))
(lazy-def 25 '(1+ 24))
(lazy-def 24 '(* 2 12))
(lazy-def 101 '(1+ 100))
(lazy-def 73 '(1+ 72))
(lazy-def 72 '(* 2 36))
(lazy-def 36 '(* 2 18))
(lazy-def 18 '(* 2 9))
(lazy-def 9 '(1+ 8))
(lazy-def 81 '(1+ 80))
(lazy-def 80 '(* 2 40))
(lazy-def 40 '(* 2 20))
(lazy-def 20 '(* 2 10))
(lazy-def 10 '(* 2 5))
(lazy-def 5 '(1+ 4))
(lazy-def 239 '(1+ 238))
(lazy-def 238 '(* 2 119))
(lazy-def 119 '(1+ 118))
(lazy-def 118 '(* 2 59))
(lazy-def 59 '(1+ 58))
(lazy-def 58 '(* 2 29))
(lazy-def 29 '(1+ 28))
(lazy-def 28 '(* 2 14))
(lazy-def 14 '(* 2 7))
(lazy-def 7 '(1+ 6))
(lazy-def 188 '(* 2 94))
(lazy-def 94 '(* 2 47))
(lazy-def 47 '(1+ 46))
(lazy-def 46 '(* 2 23))
(lazy-def 23 '(1+ 22))
(lazy-def 22 '(* 2 11))
(lazy-def 11 '(1+ 10))
(lazy-def 146 '(* 2 73))
(lazy-def 229 '(1+ 228))
(lazy-def 228 '(* 2 114))
(lazy-def 114 '(* 2 57))
(lazy-def 57 '(1+ 56))
(lazy-def 56 '(* 2 28))
(lazy-def 145 '(1+ 144))
(lazy-def 144 '(* 2 72))
(lazy-def 168 '(* 2 84))
(lazy-def 84 '(* 2 42))
(lazy-def 42 '(* 2 21))
(lazy-def 21 '(1+ 20))
(lazy-def 185 '(1+ 184))
(lazy-def 184 '(* 2 92))
(lazy-def 92 '(* 2 46))
(lazy-def 180 '(* 2 90))
(lazy-def 90 '(* 2 45))
(lazy-def 45 '(1+ 44))
(lazy-def 44 '(* 2 22))
(lazy-def 129 '(1+ 128))
(lazy-def 128 '(* 2 64))
(lazy-def 64 '(* 2 32))
(lazy-def '(ans in)
'(cons 67 (cons 111 (cons 100 (cons 101 (cons 73 (cons 81 (cons 32 (cons 239 (cons 188 (cons 146 (cons 229 (cons 145 (cons 168 (cons 229 (cons 185 (cons 180 (cons 239 (cons 188 (cons 129 (cons 10 end-of-output))))))))))))))))))))
)

(print-as-unlambda (laze 'ans))

生成されたLazyKプログラムは以下のようになります。
なお、HaskellのputChar()の仕様により、日本語部分がうまく出力できないので、C++版を使って下さい(59行目をunsignedからsize_tに変更することでコンパイルが通ります)。

codeiq2nd_lazy.lazy
`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk``s`k``s``s`ksk``skk``s``s`ksk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s``s`ksk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk``s`k``s``s`ksk``skk```s``skk``skk``s``s`ksk``skk`k``s``s``skk`k``s`k``s``s`ksk``skk``s``s`ksk```s``skk``skk``s``s`ksk``skk`k`k```s``skk``skk```s``skk``skk``s``s`ksk``skk

最後に、改めてCodeIQ2周年おめでとうございます。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?