14
1
Your boss wants you to write code like this:
public static boolean isPowerOfTen(long input) {
return
input == 1L
|| input == 10L
|| input == 100L
|| input == 1000L
|| input == 10000L
|| input == 100000L
|| input == 1000000L
|| input == 10000000L
|| input == 100000000L
|| input == 1000000000L
|| input == 10000000000L
|| input == 100000000000L
|| input == 1000000000000L
|| input == 10000000000000L
|| input == 100000000000000L
|| input == 1000000000000000L
|| input == 10000000000000000L
|| input == 100000000000000000L
|| input == 1000000000000000000L;
}
(Martin Smith, at https://codereview.stackexchange.com/a/117294/61929)
which is efficient and so, but not that fun to type. Since you want to minimize the number of keypresses you have to do, you write a shorter program or function (or method) that outputs this function for you (or returns a string to output). And since you have your very own custom full-range unicode keyboard with all 120,737 keys required for all of unicode 8.0, we count unicode characters, instead of keypresses. Or bytes, if your language doesn't use unicode source code.
Any input your program or function takes counts towards your score, since you obviously have to type that in as well.
Clarifications and edits:
- Removed 3 trailing spaces after the last
}
- Removed a single trailing space after
return
- Returning a string of output from a function/method is ok
12
0==Math.log10(input)%1
– SuperJedi224 – 2016-02-03T11:15:21.6877You say "we count unicode characters," but then you immediately say "Or bytes." Which one is it? – Doorknob – 2016-02-03T11:55:48.353
2Whichever you prefer, i.e. the one that gives you the lowest score. Added bytes to allow languages that don't use text source. – Filip Haglund – 2016-02-03T13:15:03.473
1
while(input%10==0) input/=10; return input == 1;
– PSkocik – 2016-02-03T14:20:29.1131@FilipHaglund Your comment seems to make the scoring a little unfair. I could write a program in bytecode, and say its unicode to shave off a few bytes... Maybe you meant what you stated in the question; that you should only count in unicode if your program is written in it? – YoYoYonnY – 2016-02-03T17:42:30.660
I don't want to exclude languages that don't use unicode, or languages that do use unicode. Do you have a suggested edit to the rules? It doesn't seem like anyone has used unicode yet in an answer. – Filip Haglund – 2016-02-03T17:50:44.583
@FilipHaglund The 05AB1E answer uses unicode. Unless I am wildly mistaken and "Æ£‹ÒŒ€" isn't unicode (answer was posted 4 hours prior to your comment). As to your rules, they are pretty much the standard for golf ("shortest program + input"), but presented more humorously ("pressing buttons is hard!"). – Draco18s no longer trusts SE – 2016-02-03T19:28:48.530
405AB1E uses windows CP1252, which is bytes, not unicode. I'm aiming for standard rules, but I get told I'm wrong all the time. – Filip Haglund – 2016-02-03T19:32:17.267
No bonus points for having Go generate some Java? :P – user253751 – 2016-02-04T06:06:25.470
You can have -10 bytes if you use go:generate ;) – Filip Haglund – 2016-02-04T06:09:40.227
1Most of us spent extra characters to reproduce the code and formatting. Then you post your own answer where you just use some
\t
for indentation. You could specify that from the beginning. – manatwork – 2016-02-04T10:02:18.140Woops, my bad, @manatwork . Will change that when I get back home. It should be spaces! Thanks for pointing that out. – Filip Haglund – 2016-02-04T11:25:48.770
@Dennis trailing spaces are removed, and should never have been there in the first place. – Filip Haglund – 2016-02-05T16:16:37.883
@manatwork My answer should now be correct. Please check for yourself :) – Filip Haglund – 2016-02-05T16:17:23.813
1Thanks @FilipHaglund, now the expectations are more clearly set. – manatwork – 2016-02-05T16:22:46.437
1OK, thanks. I've edited my answer. – Dennis – 2016-02-05T16:56:46.407