Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created June 3, 2020 14: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 olegchir/fecf2c551797b36a60d50691e0a4c2f4 to your computer and use it in GitHub Desktop.
Save olegchir/fecf2c551797b36a60d50691e0a4c2f4 to your computer and use it in GitHub Desktop.
package com.olegchir.jlt;
import java.util.concurrent.atomic.AtomicReference;
public class Main {
static AtomicReference<String> haystack = new AtomicReference<>("8".repeat(184));
public static void main(String[] args) {
while ( find("222") || find("888") ) {
if ( find("222") ) {
replace("222", "8");
} else {
replace("888", "2");
}
}
System.out.println(haystack.get());
}
private static boolean find(String needle) {
return haystack.get().contains(needle);
}
private static void replace(String old, String modern) {
haystack.set(haystack.get().replace(old, modern));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment