-
-
Save dbasch/f212a600f8170576db9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class y{static int s(int x){return(x<1?x:x%10+s(x/10));}public static void main(String a[]){int i=0,j=0;for(;i++<1e6;j+=s(i)==42?1:0);System.out.print(j);}} |
Nice. Most Java people are probably still not used to the functional style, but it does make the language less verbose :)
Java 8 does improve things. I actually tried to change your for loop to use Java 8 as well:
java.util.stream.IntStream.range(0, 1000000).filter(x->(x+"").chars().map(x->x-48).sum()==42).count()
Although arguably more readable, your crazy minified for loop ended up shorter due to the need to import IntStream
and spell out 1e6
fully :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a shorter version using Java 8: