Java - 334
import java.nio.*;public class a{public static void main(String[]i)throws Exception{String s=new String(Files.readAllBytes(Paths.get(i[0])));int l=s.replaceAll("\\d","").length(),L=s.length()-l,a=1,b=2,c,d=0;while(a<L){if(a==l&&b==L)d=1;c=b;b+=a;a=c;}System.out.printf("Digits: %s Nondigits: %s\n%salid Program",L,l,d==0?"Inv":"V");}}
Ungolfed:
import java.nio.file.*;
public class Testing {
public static void main(String[] i) throws Exception {
String s = new String(Files.readAllBytes(Paths.get(i[0])));
int l = s.replaceAll("\\d", "").length(), L = s.length() - l, a = 1, b = 2, c, d = 0;
while (a < L) {
if (a == l && b == L) {
d = 1;
}
c = b;
b += a;
a = c;
}
System.out.printf("Digits: %s Nondigits: %s\n%salid Program", L, l, d == 0 ? "Inv" : "V");
}
}
Explanation:
Reads the input from the file
supplied by command line
Puts the contents in a String
oh no! I'm thinking of quines.
Regex swaps digits of that thing
for the one and only empty String.
Then by String#length()
I find
the charcount nondigit, yes that kind.
From the length of the first String
I subtract the charcount nondigit thing
to find the char digits count.
Next I sweep it all under the rug
so I can say "Help I'm a bug!".
Then I retrieve it - please have patience.
Now the first terms of the Fibonacci sequence
used to find the rest of the numbers.
What to rhyme with? I'll just use "others".
And when small num is greater than non-digits
I know if it's true, so wait a minute.
Uses printf
to format output.
"alid Program"
at the start puts
"Inv"
or "V"
according to the answer
Before is the counts, not one thing fancier
Thank you for lis'ning to this tale
Of the program that validates according to your rules
Whew, it was hard to write that.
I decided to assume the input is from the command line, in the form of a String. Please correct me, because if I can simply take a File
as input, I can shorten this by a few chars. Also, I'd like to know if a method is okay.
You may want to clarify the order of the consecutive Fibonacci numbers in Rule 3. It is currently a bit ambiguous and possibly opposite to the other question.
– Darren Stone – 2014-01-21T01:21:51.1771Also, your examples are contrary to each other: 34 & 21 should not be both valid and invalid. Probably a typo. – Darren Stone – 2014-01-21T01:36:14.180
looks good now! :-) – Darren Stone – 2014-01-21T01:45:19.627
I see you like my validator. Interesting how my code is forked 5 times... – Justin – 2014-01-21T05:06:07.100
@Quincunx Completely a duplicate! Sorry about that folks! – None – 2014-01-21T06:06:10.467
1Ouch, that rule about explaining in rhyme; it hurt my brain more than any program I wrote here. – Justin – 2014-01-21T06:13:51.800