创建一个程序,使用不内置的阶乘函数计算数字的阶乘。容易吗?问题是,您必须以柴歌形式编写整个程序(包括测试程序)。

你可以随心所欲地使用多少句话,但发音时,它们必须遵循5-7-5音节的格式。
这是一个人气-竞赛,所以你必须赢得最多的选票。你的程序必须包括至少一个完整的haiku,并且所有的haikus必须是完整的。
当阅读代码时,每句话的第一行将有5个音节,第二行将有7个音节,第三行将有5个音节。
发布于 2014-02-17 03:30:49
(在工作区中进行评估;打开一个对话框,请求一个数字并在stdout上打印结果):
"in" "this" 'poem,' "you" "must"
"pronounce" "characters" "like" "these:"
"return(^)," "and" "times(*);" "please".
"but" 'never' "in" "here"
"tell" "anyone" "about" "those"
"few" "parentheses".
"otherwise" "these" "words"
"are" "stupid" "and" "this" "coded"
"rhyme" "is" "wasted" Time.
"let" "us" "now" "begin"
"by" "defining," "in" Object
"and" compile: "the" "rhyme:"
'fac: "with" arg"ument"
"to" "compare" arg <"against" 2 ">"
"and" ifTrue: [ ^"return"
"["1] "or" ifFalse: "then"
["return"^ arg *"times" "the" "result"
"of" ("my"self ")getting"
"the" fac:"torial"
"of" "the" "number" arg "minus"-
1 "[(yes," "its" "easy")]'.
("Let" "me" "my"self "ask"
"for" "a" "number," "to" "compute"
"the" fac:"torial"
("by" "opening" "a"
"nice" Dialog "which" "sends" "a"
request: "asking" "for"
'the Number to use'
"(which" "is" "(" "treated" ) asNumber)
"then" print "the" "result".我也试着带来一些反思(“在这首诗中”)和奇戈。此外,还包括一些西方风格的押韵元素(请->这些,时间->押韵);但是,既不是以日语为母语,也不是英语,请原谅任何文体细节;-)
发布于 2014-02-17 02:10:39
protected static
int factorial(int n) {
if (n == 0) {
return n + 1;
} return factorial(n
- 1) * n;}即使问题不是密码-高尔夫,我也经常发现自己在打高尔夫球。在这种情况下,我打出了猜句的数量。
我宣布如下:
受保护的静态整数乘整数n如果n为零返回n+1 返回阶乘n减去1乘n
测试程序:
class Factorial { // class Factorial
public static void main(String[] // public static void main string
command_line_run_args) { // command line run args
int i = 0; // int i is zero
while (7 != 0) // while seven is not zero
System.out. // System dot out dot
println(i + "!" // print line i plus not
+ " = " + factorial( // plus is plus factorial
i += 1));} // i plus equals 1
protected static
int factorial(int n) {
if (n == 0) {
return n + 1;
} return factorial(n
- 1) * n;}}注意,这个程序开始快速输出0s,这是溢出的结果。通过将每个int更改为long,您可以很容易地获得更大的正确数字。
System.out.println和public static void main(String[] args)的标准发音反映在程序中。
发布于 2014-02-17 02:22:36
fact :: Int -> Int -- fact is Int to Int
fact x = product (range x) -- fact x is product range x
range x = [1..x] -- range x is 1 [pause] xHaskell教育时间:
range x函数创建一个从1到x值的整数列表。fact x函数将列表range x的所有值相乘,以计算结果。fact函数接受一个整数并返回一个整数。https://codegolf.stackexchange.com/questions/21095
复制相似问题