Influenced by Non-discriminating Programming, I made up an idea of a similar challenge.
Here, we say a string is a Lucas string if the number of appearances of each character is a Lucas number (2, 1, 3, 4, 7, ...), and a string is a Fibonacci string if the number of appearances of each character is a Fibonacci number (1, 2, 3, 5, 8, ...).
Here are some concrete examples:
"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
All counts are both Lucas numbers and Fibonacci numbers, so this is both a Lucas string and a Fibonacci String
"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
All counts are Lucas numbers, so this is a Lucas string. However the count of o
is not a Fibonacci number, so this is not a Fibonacci string.
"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
All counts are Fibonacci, so this is a Fibonacci string. However the counts of and
e
are not Lucas numbers, so this is not a Lucas string.
"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
Since count of i
is not Lucas number, and count of n
is not Fibonacci number, so this is neither a Lucas string nor a Fibonacci String.
Challenge
Write 2 programs, one Lucas program and one Fibonacci program, both accepting a string as input, that:
- The Lucas program checks whether the input is Fibonacci; and
- The Fibonacci program checks whether the input is Lucas,
where the definitions of "Lucas" and "Fibonacci" are as above.
Rules
- Your programs can choose to receive input either from STDIN or as function/program argument.
- Your programs must output or return one of the 2(TWO) distinct values at your choice, one for the truthy value and one for the falsy value, and the choice must be consistent across the programs, i.e. you cannot have one program returning
0/1
while the other one returningtrue/false
. - Your programs must output or return a truthy value if the source of each other is inputted, i.e. your Lucas program must return a truthy value if the source of your Fibonacci program is inputted, and vice versa.
- It is allowed to have program being both Lucas and Fibonacci.
- Characters not used are apparently not counted, in case you doubt because 0 is not in the Lucas sequence.
- Number of distinct characters in each program are not restricted to either Lucas or Fibonacci numbers.
- Only full programs or functions allowed. Snippets are not accepted.
- Standard loopholes are apparently forbidden.
Scoring
The score will be calculated as follows:
- For each program, multiply
the number of distinct characters used
bythe maximum number of appearances of the characters in the source
. - Add the two values calculated in the previous step up. This is your score.
Example:
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 = 290
Test cases
Input | 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) | |
Winning Criteria
The submission with the lowest score in each language wins.