Count the score of a Code Golf code

0

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.

2br-2b

Posted 2018-11-26T21:21:03.000

Reputation: 101

Question was closed 2018-11-26T21:48:16.147

I'm voting to close this question as off-topic because it's basically just asking for a minifier – Sparr – 2018-11-26T21:28:54.610

So this program should just remove unneeded whitespace and count the length of the result? – Poke – 2018-11-26T22:21:13.557

2If it's more complicated than that I fear something something halting problem – Poke – 2018-11-26T22:23:08.727

@Sparr There are a few key differences: 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 is to help the user get a lower score without substantially changing their program. – 2br-2b – 2018-11-26T22:30:31.320

Basically @Poke – 2br-2b – 2018-11-26T22:31:02.957

1Note 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. – Jo King – 2018-11-27T03:17:32.077

So would you suggest that I open it to any language written (but still simplifying Java), to make it for any language on itself, or to just leave it closed? – 2br-2b – 2018-11-27T03:20:07.880

2

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.

– Jo King – 2018-11-27T03:23:53.963

No answers