0
\$\begingroup\$

This question already has an answer here:

My challenge is to make a Java method(s) that is given a String (another code in Java), removes any unnecessary characters, counts and returns the score, and displays the cleaned-up code in a way that can be copied/pasted.

It should ignore spaces, line breaks, etc. unless they are necessary to the code.

For example, if the space in the string int number=3; was removed to make it intnumber=3; (and remove a bit), there would be a compiler error if the counted program were run. However,

int      
number   =

3           ;

would return 13, the same as the previous two examples.

The program with the least characters as calculated by the program you write (note - this does not mean you can just make it return 0; or something like that) wins!

Note - the code must be in Java. This Java code cannot call code of another language. If there is a loophole, please ask in a comment before posting an answer!


Note: there are a few key differences between this challenge and the other one:

  • You have use Java
  • You must return the number of characters after having removed spaces, etc.
  • You leave the variable names, etc. as are. For this, the score should ignore line breaks, spaces, and other characters skipped over by the compiler when counting. The other program required you to reduce variable names, remove comments, etc.

To be clear, this is primarily a score checker. The code reducing in this program is to help the user get a lower score without substantially changing their program.

\$\endgroup\$

marked as duplicate by xnor, Sparr, Jo King code-golf Nov 26 '18 at 21:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ I'm voting to close this question as off-topic because it's basically just asking for a minifier \$\endgroup\$ – Sparr Nov 26 '18 at 21:28
  • \$\begingroup\$ So this program should just remove unneeded whitespace and count the length of the result? \$\endgroup\$ – Poke Nov 26 '18 at 22:21
  • 2
    \$\begingroup\$ If it's more complicated than that I fear something something halting problem \$\endgroup\$ – Poke Nov 26 '18 at 22:23
  • 1
    \$\begingroup\$ Note that restricting a challenge to a single language usually isn't seen as a good thing, especially if the challenge is a subset of an already existing challenge, like this one. If this question is re-opened, I would expect it to get downvoted. \$\endgroup\$ – Jo King Nov 27 '18 at 3:17
  • 2
    \$\begingroup\$ I would suggest leaving this closed and try posting future challenges in the Sandbox to try to get feedback and gauge whether the question will be well-received. \$\endgroup\$ – Jo King Nov 27 '18 at 3:23