fork download
  1. class Main{
  2. interface N{
  3. String c(String s);
  4. }
  5.  
  6. static N m =
  7.  
  8. // The actual code:
  9. s->{s+=" ";String r="",t,y,z[]="ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE".split(" ");for(int i=0,j,l,b;i<9;){for(j=b=0;j<(l=(y=z[i]).length())&s.length()>3;b+=s.substring(0,l).split(t=""+y.charAt(j++),-1).length==y.split(t,-1).length?1:0);if(b==l){s=s.substring(l);r+=i+1;}else i++;}return r;}
  10.  
  11. ;
  12.  
  13. public static void main(final String[] a){
  14. final Main m = new Main();
  15. System.out.println(m.m.c("NEO"));
  16. System.out.println(m.m.c("ENOWOT"));
  17. System.out.println(m.m.c("EONOTWHTERE"));
  18. System.out.println(m.m.c("SNVEEGHEITNEIN"));
  19. System.out.println(m.m.c("ENOOWTEERHTRUOFEVIFXISNEVESTHGIEENIN"));
  20. System.out.println(m.m.c("NOEWOTTOWHEERT"));
  21. }
  22. }
  23.  
  24. /**
  25. Ungolfed and explanation:
  26.  
  27. s->{ // Method with String as parameter and return-type
  28.   s+=" "; // Append 3 spaces, to prevent an StringIndexOutOfBoundsException when checking i.e. "THREE" of length 5, on a length 3 input
  29.   String r="", // Result-String
  30.   t,y, // Temp Strings
  31.   z[]="ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE".split(" ");
  32.   // String-array of "ONE" through "NINE"
  33.   for(int i=0,j,l,b;i<9;){ // Loop (1) from 0 to 9 (exclusive)
  34.   for(j=b=0; // Set `j` and `b` both to 0
  35.   j<(l=(y=z[i]).length()) // Inner loop (2) over the characters of the current String-representation
  36.   &s.length()>3; // and as long as the remaining input-String is at least of length 3 (or 0 if we exclusive the three spaces)
  37.   b+= // Raise `b` by:
  38.   s.substring(0,l).split(t=""+y.charAt(j++),-1).length==y.split(t,-1).length?
  39.   // If the amount of occurances of the current character in both Strings is the same
  40.   1 // Raise `b` by 1
  41.   : // Else:
  42.   0 // `b` remains the same
  43.   ); // End of inner loop (2)
  44.   if(b==l){ // If `b` now equals `l`, which means it matches the current String-representation
  45.   s=s.substring(l); // Remove this substring from the input
  46.   r+=i+1; // And append this number to the result-String
  47.   }else // Else:
  48.   i++; // Raise `i` to go to the next number
  49.   } // End of loop (1)
  50.   return r; // Return the result-String
  51. } // End of method
  52.  
  53. **/
Success #stdin #stdout 0.08s 711168KB
stdin
Standard input is empty
stdout
1
12
123
789
123456789
1223