Skip to content

Instantly share code, notes, and snippets.

@chiliec
Created September 30, 2020 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiliec/0f689ee5c08ea595300707fe835933b2 to your computer and use it in GitHub Desktop.
Save chiliec/0f689ee5c08ea595300707fe835933b2 to your computer and use it in GitHub Desktop.
Find all transport tickets with "lucky" numbers
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