在无差别编程的影响下,我提出了一个类似挑战的想法。
这里,如果每个字符的外观数是Lucas数(2,1,3,4,7,.),那么字符串就是Lucas字符串,如果每个字符的外观数是Fibonacci数(1,2,3,5,8,.),则字符串就是Fibonacci字符串。
以下是一些具体的例子:
"Programming Puzzles"
Appearance Count: P a e g i l m n o r s u z
1 2 1 1 2 1 1 2 1 1 2 1 1 2所有计数都是Lucas数和Fibonacci数,因此这既是Lucas字符串,也是Fibonacci字符串。
"Sandbox for Proposed Challenges"
Appearance Count: C P S a b d e f g h l n o p r s x
3 1 1 1 2 1 2 3 1 1 1 2 2 4 1 2 2 1所有的计数都是卢卡斯的数字,所以这是卢卡斯的字符串。但是,o的计数不是Fibonacci数,所以这不是Fibonacci字符串。
"Here are some concrete examples: "
Appearance Count: : H a c e l m n o p r s t x
5 1 1 2 2 8 1 2 1 2 1 3 2 1 1所有计数都是Fibonacci,所以这是Fibonacci字符串。然而,和e的计数不是Lucas数,所以这不是Lucas字符串。
"Non-discriminating Programming"
Appearance Count: - N P a c d g i m n o r s t
1 1 1 1 2 1 1 3 5 3 4 2 3 1 1因为i的计数不是Lucas数,n的计数也不是Fibonacci数,所以这既不是Lucas字符串,也不是Fibonacci字符串。
编写两个程序,一个Lucas程序和一个Fibonacci程序,它们都接受字符串作为输入,即:
其中,"Lucas“和"Fibonacci”的定义如上。
0/1,而另一个返回true/false。分数计算如下:
the number of distinct characters used乘以the maximum number of appearances of the characters in the source。示例:
Lucas code : 20 distinct characters, MAX(appearance of each character)=7
Fibonacci code: 30 distinct characters, MAX(appearance of each character)=5
Score: 20*7 + 30*5 = 140 + 150 = 290Input | Output of ...
| Lucas Program | Fibonacci Program
----------------------------------------+---------------------------------------
<Your Lucas program> | True if all appe- | True
(Lucas string by rules) | arance counts are |
| exactly 1, 2 or 3; |
| False otherwise |
----------------------------------------+--------------------+------------------
<Your Fibonacci program> | True | True if all appe-
(Fibonacci string by rules) | | arance counts are
| | exactly 1, 2 or 3;
| | False otherwise
----------------------------------------+--------------------+------------------
"Programming Puzzles" | True | True
(Both Lucas and Fibonacci) | |
----------------------------------------+--------------------+------------------
"Sandbox for Proposed Challenges" | False | True
(Lucas but not Fibonacci) | |
----------------------------------------+--------------------+------------------
"Here are some concrete examples: " | True | False
(Fibonacci but not Lucas) | |
----------------------------------------+--------------------+------------------
"Non-discriminating Programming" | False | False
(Neither Lucas nor Fibonacci) | |
----------------------------------------+--------------------+------------------
"Hello world!" | True | True
(Both Lucas and Fibonacci) | |
----------------------------------------+--------------------+------------------
"18446744073709551616" | False | True
(Lucas but not Fibonacci) | |
----------------------------------------+--------------------+------------------
"Lucas and Fibonacci are IN pair" | True | False
(Fibonacci but not Lucas) | |
----------------------------------------+--------------------+------------------
"Lucas and Fibonacci are in pair" | False | False
(Neither Lucas nor Fibonacci) | |在每种语言中得分最低的投稿获胜。
发布于 2018-08-24 08:28:37
这可能是对Kevin帖子的评论,但我已经独立开发了它,技术也略有不同。因此,我是自己张贴它。
€¢Dā0šÅgÃQ€¢Dā0šÅgÃQ -> Full program
€¢ -> Count the occurrences of each character in the string. Call this list C.
Dā -> Duplicate and yield the range [1 ... len string].
0š -> Prepend 0. [0 ... len string].
Åg -> Nth Lucas number (for each).
à -> Intersection with C.
Q -> Check equality with C.€¢DāÅfÃQ€¢DāÅfÃQ -> Full program
€¢ -> Count the occurrences of each character in the string. Call this list C.
Dā -> Duplicate and yield the range [1 ... len string].
Åf -> Nth Fibonacci number (for each). We don't need the 0th this time!
à -> Intersection with C.
Q -> Check equality with C.发布于 2018-08-24 13:57:58
两者都返回0为真实,1为虚假。
Fibonacci试验:
ĐỤ⇹ɔ2ᴇřḞ\ٱ卢卡斯试验:
ĐỤ⇹ɔ02ᴇŘĿ\ٱ解释:
Implicit input
Đ Duplicate the input
Ụ Get list of unique characters
⇹ Swap the top two elements on the stack
ɔ Count the number of occurrences of each character in the input
2ᴇř Push [1,...,100] (should be more than enough)
Ḟ Get the first 100 Fibonacci numbers
\ Get all character counts that aren't Fibonacci numbers
Ł Get the number of such counts
± Output the sign of the number of such counts
Implicit output Implicit input
ĐỤ⇹ɔ get count of occurrences of each character
02ᴇŘ Push [0,1,...,100] (should be more than enough)
Ŀ Get the first 101 Lucas numbers
\ Get all character counts that aren't Lucas numbers
Ł Get the number of such counts
± Output the sign of the number of such counts
Implicit outputhttps://codegolf.stackexchange.com/questions/171122
复制相似问题