+>>,[<++++[----->>->+>+<<<<]----[---->-<]>->+>[--<<-[<]<[>>>+<<]>>>]<<------>>>[--<<<-[<]<[>>>+<<]>>>>]<<<,]>.
Try it online!
Accepts input as ASCII. outputs as binary. The header adds 48 (ASCII 0) to the count so that small outputs appear as ASCII digits.
This is a complete rewrite of my previous answer below, taking into account everything I could have done better. In particular, I set up a specific cell with a 1 in it to help with the IF operation instead of trying to use other nonzero cells to assist.
There are a few more bytes to save with this approach if I have time later. It's still the highest scoring answer, but it isn't the longest anymore, which is gnerally as good as it gets with Brainfuck.
+>> Put a 1 in cell 0 then move to cell 2
,[ take an input in cell 2 and loop until end of string marked by 0 encountered
<++++[----->>->+>+<<<<] Put 260 mod 256=4 in cell 1; iterate 260/5=52 times to subtract 52 from cell 3 and store 52 in cells 4 and 5
----[---->-<]>- Put minus 4 = 252 in cell 1; iterate 252/4=63 times to subtract 63 from the input; then reduce by one more
>+> add 1 to cell 3
[--<<-[<]<[>>>+<<]>>>] iterate 26 times UPPERCASE using 52 in cell 4; if not zero add 1 to cell 3
<<------>>> subtract 6 from the input
[--<<<-[<]<[>>>+<<]>>>>]iterate 26 times LOWERCASE using 52 in cell 5; if not zero add 1 to cell 3
<<< overall cell 3 has increased by 0 if input is a letter or 1 if not a letter
,] take more input into cell 2 until end of string marked by 0 encountered
>. output count from cell 3
,[<++++[-----<-<+<+<+>>>>]>----------<<<<<[->>>>>-<<<<<]>>>>>--<<<<[-->>>>-[<]<[+>]<<<]>>->>------<<<[-->>>-[<]<[+>]<<]>++[->>>+<<<]>>,]>.
I misread the question and assumed all characters except AZaz
and newline should be counted. I now realise newlines need to be counted like any other non AZaz
character which makes the code slightly shorter. If I had not considered newlines at all, the code might be shorter still, but the setup loop 260/5=52=2*26 is pretty efficient.
Try it online!
Accepts input as ASCII. outputs as binary. The header adds 48 (ASCII 0) to the count so that small outputs appear as ASCII digits.
Commented code
,[ Take an input; If nonzero start looping
<++++ Move left and add 4 to make (256+4)=260 mod 5
[-----<-<+<+<+>>>>]> Loop 52 times to setup 3 cells with 52 and one with minus 52
----------< Subtract 10 from input
<<<<[->>>>>-<<<<<]>>>>>-- Subtract another 52+2=54 from the input
<<<<[-->>>>- Loop 52/2=26 times reducing the input by 1 each time for UPPERCASE
[<]<[+>] If the input is nonzero increment the cell that contained minus 52
<<<] Ultimately the cell with minus 52 will be incremented 51 times for AZaz 52 for other
>>->>------ Subtract 1 from cell that contained minus 52 to avoid it reaching 0; and 6 from input
<<<[-->>>- Loop 52/2=26 times reducing the input by 1 each time for LOWERCASE
[<]<[+>] If the input is nonzero increment the cell that contained minus 52
<<]
>++ Cell that contained minus 52 now has minus 2 for AZaz or minus 1 for other; increment by 2
[->>>+<<<] Copy the value 0 or 1 into the final total
>>,] Take the next input and if nonzero continue to loop
>. Output the final total