gpt4 book ai didi

language-agnostic - Code Golf : Print the entire "12 Days of Christmas" song in the fewest lines of code

转载 作者:行者123 更新时间:2023-12-03 10:30:23 26 4
gpt4 key购买 nike

锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或互动。








打印 popular holiday song 的所有 12 节经文.

我所说的 12 节是指歌曲中所唱的每一行的重复,即

诗一:
在圣诞节的第一天,我的真爱给了我
梨树上的鹧鸪。

第二节
在圣诞节的第二天,我的真爱给了我
两只斑鸠
和梨树上的鹧鸪。

...

第 N 节:
在圣诞节的第n天我的真爱给了我
(没有第一行的第 N-1 节)
(在第 N 节中添加的行)

最佳答案

通用 Lisp:

(mapc #'princ
(reverse (maplist #'(lambda(l)
(format nil
"On the ~:R day of Christmas my true love gave to me~%~{~a~%~}~%"
(length l) l))
'("twelve drummers drumming,"
"eleven pipers piping,"
"ten lords a-leaping,"
"nine ladies dancing,"
"eight maids a-milking,"
"seven swans a-swimming,"
"six geese a-laying,"
"five gold rings,"
"four calling birds,"
"three french hens,"
"two turtle doves, and"
"a partridge in a pear tree."))))

编辑:

如果去掉空格,上面是 412 个字符。

这个:
(let ((g))
(dotimes (i 12)
(format t
"On the ~:R day of Christmas my true love gave to me~%~{~R ~:*~
~[~;~;turtle doves and~;french hens,~;calling birds,~;gold rings,~
~;geese a-laying,~;swans a-swimming,~;maids a-milking,~
~;ladies dancing,~;lords a-leaping,~;pipers piping,~
~;drummers drumming,~]~%~}a partridge in a pear tree~2%"
(1+ i) g)
(push (+ i 2) g)))

如果在格式字符串中去掉空格和 ~ 引用的换行符,则为 344 个字符:
(let((g))(dotimes(i 12)(format t"On the ~:R day of Christmas my true love gave to me~%~{~R ~:*~[~;~;turtle doves and~;french hens,~;calling birds,~;gold rings,~;geese a-laying,~;swans a-swimming,~;maids a-milking,~;ladies dancing,~;lords a-leaping,~;pipers piping,~;drummers drumming,~]~%~}a partridge in a pear tree~2%"(1+ i)g)(push(+ i 2)g)))

编辑:

看起来这个问题已经结束了,该网站正在唠叨我接受答案。据我所知,这个是最短的。如果我接受自己的答案,我有点害怕该网站会做什么 - 可能会给我一个自恋者或手淫者徽章。

你不能接受自己的答案。很公平。我会保持打开状态。感谢大家的回应。

关于language-agnostic - Code Golf : Print the entire "12 Days of Christmas" song in the fewest lines of code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/383403/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com