代码高尔夫:决策树 [英] Code Golf: Decision Tree

查看:262
本文介绍了代码高尔夫:决策树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google Code Jam 2009中,第1B轮,一个称为决策树"的问题,可以使自己获得相当有创意的解决方案.

In Google Code Jam 2009, Round 1B, there is a problem called Decision Tree that lent itself to rather creative solutions.

发布您最短的解决方案;假设您不只是为了解决这个问题而创建新的语言,我将每半频繁地将接受的答案"更新为当前最短的条目. :-P

Post your shortest solution; I'll update the Accepted Answer to the current shortest entry on a semi-frequent basis, assuming you didn't just create a new language just to solve this problem. :-P

当前排名:

  • 107 Perl
  • 121 PostScript (binary)
  • 132 Ruby
  • 154 Arc
  • 160 PostScript (ASCII85)
  • 170 PostScript
  • 192 Python
  • 196 JavaScript
  • 199 Common Lisp
  • 212 LilyPond
  • 273 Scheme
  • 280 R
  • 281 sed w/ bc
  • 312 Haskell
  • 314 PHP
  • 339 m4 w/ bc
  • 346 C
  • 381 Fortran
  • 462 Java
  • 718 OCaml
  • 759 F#
  • 1554 sed
  • C++ not qualified for now

推荐答案

Perl(107个字符)

say("Case #$_:"),
$_=eval"''".'.<>'x<>,
s:[a-z]+:*(/ $&\\s/?:g,s/\)\s*\(/):/g,
eval"\$_=<>;say$_;"x<>for 1..<>

换行符以提高可读性;它们都不是必需的或无用的.

Newlines for legibility; none of them is necessary or counted in.

它使用的功能仅在最新版本的Perl中才能找到,因此可以在perl -M5.010或更高版本上运行.

It uses features found only in the latest versions of Perl, so run with perl -M5.010 or later.

我也曾经是Perl的新手,因此它的工作原理与红宝石的工作原理几乎相同.原始版本126个字符,由peutri优化.

I used to be a Perl noob too, so this works almost the same as the ruby one. Original version 126 chars, optimizations by peutri.

反向链接:

字对齐-超级编程

这篇关于代码高尔夫:决策树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆