Created
September 30, 2020 19:23
-
-
Save chiliec/0f689ee5c08ea595300707fe835933b2 to your computer and use it in GitHub Desktop.
Find all transport tickets with "lucky" numbers
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
public class App { | |
public static void main(String[] args) { | |
for (int i = 0; i <= 999999; i++) { | |
if (isLuckyTicket(i)) { | |
System.out.println(i); | |
} | |
} | |
} | |
private static boolean isLuckyTicket(int ticketNumbers) { | |
byte[] c = String.format("%06d", ticketNumbers).getBytes(); | |
return c[0]+c[1]+c[2]==c[3]+c[4]+c[5]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment