8
1
Create a program that returns True if a given input meets the following specifications, and False otherwise:
- The count of numeric characters (0-9) in the input matches a Fibonacci number.
- The count of non-numeric characters !(0-9) in the input matches the Fibonacci number immediately preceding the count of numeric characters.
Additional Rules:
- Your program must use the proper Fibonacci sequence, per OEIS - that is, the Fibonacci sequence must start with
0, 1, 1, 2, ...
- If the numerics or non-numerics count is 1, the following must occur:
- Numerics 1: Non-numeric count of 0 or 1 should be handled as True - all others False.
- Non-Numerics 1: Numerics count of 1 or 2 should be handled as True - all others False.
- Input may be taken however you like, but the program must be capable of handling any arbitrary text.
- True/False are not case-sensitive, and can be substituted with 1/0 or T/F.
- You may only hard-code up to two Fibonacci numbers.
- Output may only be True/False or 1/0 or T/F. Any additional text or visible errors generated is unacceptable.
give some example IO – Shubanker – 2014-01-19T07:13:03.040
@Subhanker See the linked question for some example True cases. – Iszi – 2014-01-19T07:13:42.037
Relevant wikipedia article: http://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers
– Justin – 2014-01-19T07:33:20.957is T/F or T/nil acceptable as well? – John Dvorak – 2014-01-19T07:52:38.987
Am I right that we can either output or return? – Justin – 2014-01-19T08:08:58.213
@Quincunx I interpret it as "output". I believe a return value is acceptable. – John Dvorak – 2014-01-19T08:09:48.870
@JanDvorak I'm honestly not sure which language to use right now, so I'd like to keep my options open. I interpret the same as you. – Justin – 2014-01-19T08:10:56.253
@Quincrux Output preferably, but since there's already some answers I won't modify the challenge. – Iszi – 2014-01-20T00:24:29.323
@JanDvorak T/F is okay, but I wouldn't be too keen to accept T/nil. – Iszi – 2014-01-20T00:31:37.337
@Iszi T/nil is the standard representation of booleans in Lisp. That's why I'm asking. – John Dvorak – 2014-01-20T04:23:23.267
"You may only hard-code up to two Fibonacci numbers." - you're changing this rule too often (even one invalidating change counts as too often). Why not drop it entirely? – John Dvorak – 2014-01-20T05:46:33.043
@JanDvorak That seems to be a rather unique case I'd rather not mess with re-writing a rule (again) for. Sorry. As it is, I've added a fair bit since the start of this challenge already. I'd rather not edit it any more if I can get away with it. I thought this was going to be relatively simple, but perhaps it could have used some time in the Sandbox (AKA: Black Hole of My Ideas). – Iszi – 2014-01-20T05:46:41.553
@JanDvorak The original rule was to not hard-code Fibonacci numbers at all, which is a rather general statement of the rule's intent. However, some people (yourself included) took it a bit too literally and started writing disclaimers like "well, I had to hard-code a couple..." into their answers. I modified it to allow for the first two, because those are the bare essentials needed to start generation of the sequence. Then someone (oh, that was you again) requested a generalization of the rule to allow for the second and third numbers instead... – Iszi – 2014-01-20T05:52:36.750
...I'm done editing that rule. It's now strict enough to serve its purpose while still being just permissive enough to allow programs to be functional - which is how I like my rules to be in general anyway. – Iszi – 2014-01-20T05:54:05.227
You've still invalidated the first revision of my javascript solution. You might just say "you may not hard code the entire fibonacci sequence", but that's hardly beneficial because such sequence would be longer than the generator. – John Dvorak – 2014-01-20T05:56:09.723
@JanDvorak Your current revision is shorter, and fits the current version of the anti-hard-coding rule. I fail to understand why you would complain about that particular rule at this point. – Iszi – 2014-01-20T06:00:01.203
2Ugh, you changed the challenge. Now you say that the fibonacci sequence starts at 0 and give specific cases for 0. The other question that you linked to forbids 0, so I assumed the same. – Justin – 2014-01-21T04:47:03.067