• Source
    1. ** memory layout:
    2. * OICag
    3. * O: outer loop counter ( 50 downto 1 )
    4. * I: inner loop counter ( 26 downto 1 )
    5. * C: output character
    6. * a: case flag ( minus 1 if upper case 0 if lower case )
    7. * g: global counter ( 0 to 1299 )
    8. **
    9. * outer loop ( input a SP(32) )
    10. ,[-->+++<]>O++[-
    11. * inner loop ( duplicate comma to skip a NL )
    12. >,,I++>+++++[-<+++++>]<I[
    13. I[->C->+<<]
    14. >>-[-<<I+>>]
    15. * create a capital alphabet
    16. +++++++[-<C+++++++++++++>]
    17. * switch with g
    18. * if 0 ( 1 ) do nothing
    19. * else judge if g plus 1 is prime / has some "3" digit
    20. * memory layout:
    21. * agG
    22. * G: backup of g
    23. >g[
    24. * set minus 1 ( default: upper ) to a
    25. <a->
    26. * memory layout:
    27. * a_G_nm
    28. * n m: g plus 1
    29. * copy g plus 1 to n and m
    30. g+[->G+>>n+m>+<<<<]
    31. >G-
    32. >>>m[
    33. * divmod m by 10
    34. * memory layout:
    35. * a_g_nmdrq
    36. * d: dividor(10) then 10 minus r
    37. * r: reminder
    38. * q: quotient
    39. >d++++++++++<m[->-[>+>>]>[+[-<+>]>+>>]<<<<<]
    40. * if r=3 ( lower case ) increment a and clear d q n
    41. >>r---[,+d<,+r>]<d[,+>>q,+<<<<n,+<<<<a+>>>>>>]
    42. * move q to m
    43. >>q[-<<<m+>>>]
    44. <<<m]
    45. * prime judge
    46. * subtract d*d from n ( underflow aware ) then judge if n is divisible by d
    47. * memory layout:
    48. * a_G_nd
    49. * d: incremental odd divider ( set 0 when the judge ends )
    50. d+[+
    51. * memory layout:
    52. * a_G_nd
    53. * a_GNc__Ddn
    54. * N: a copy of n
    55. * c: loop counter ( initially d )
    56. * D: counterblnce of d
    57. * move n
    58. <[-<N+>>>>>>n+<<<<<]
    59. * move d
    60. >[-<+>>>>+<<<]
    61. * subtraction loop
    62. <c[-
    63. >>>>d[
    64. >[n-<<D+<]
    65. * clear d D when underflow detected
    66. <[d,++<,+<<]
    67. >>>d-]
    68. * restore d from D ( when no underflow occurred )
    69. <D[->d+<]
    70. <<<c]
    71. * judge if n minus d*d is divisible by d
    72. * memory layout:
    73. * a_GNn__rdx
    74. * x: n minus d*d
    75. * r: reminder of x/d
    76. * restore original n
    77. <N[->n+<]
    78. >>>>>d[
    79. * mod x by d ( no quotient )
    80. >x[-<-[<+<]<[+[->+<]<<]>>>>]
    81. * restore original d from r d when x is not divisible by d
    82. <<r[[-<<+>>]>d[-<<<+>>>]<r]
    83. * when divisible clear d and increment a
    84. >d[,+<<<<<<<<a+>>>>>>>>d]
    85. d]
    86. <<<d] ** notice this d is at the original place
    87. ** clear n
    88. <n,+<<<
    89. g]
    90. * restore g from G ( and increment )
    91. >G+[-g<+>]
    92. * tolower
    93. <<a+[+++[-<c++++++++>]]
    94. * putc
    95. <C.,+
    96. <I]
    97. <O]
    98.