Java 7中,622个 619 618字节
import java.util.*;void c(){Random r=new Random();List<Long>l=new ArrayList();int i=0,c=r.nextInt(6)+5;for(;i++<c;l.add(r.nextInt(20)+1L));p(l);if(l.contains(7)){for(i=0;i<c;l.set(i,l.get(i++)-1));p(l);}if(l.contains(0)){for(i=0;i<c;l.set(i,l.get(i++)+1));p(l);}if((i=l.indexOf(13))>=0){for(;i<l.size();l.remove(i));p(l);}if(l.contains(2)){for(i=0;i<l.size();)if(l.get(i)%2>0)l.remove(l.get(i));else i++;p(l);}if(l.contains(20)){p(20*(l.get(2)%2<1?1:l.size()));return;}i=0;for(long x:l)i+=x;for(;i>50;)i-=l.remove(l.size()-1);p(l);if(l.contains(16))p(Byte.valueOf(i+"",16));p(i);}<T>void p(T t){System.out.println(t);}
-1字节感谢@Poke
说明:
import java.util.*; // Imports used for List, ArrayList and Random
void c(){ // Main method
Random r=new Random(); // Random generator
List<Long>l=new ArrayList(); // The list
int i=0, // Temp index we use multiple times
q=r.nextInt(6)+5; // Random size of the list (5-10)
for(;i++<q;l.add(r.nextInt(20)+1L)); // Fill the list with random long-integers (1-20)
p(l); // Print the initial list
if(l.contains(7)){ // If the list contains a 7
for(i=0;i<c;l.set(i,l.get(i++)-1)); // Decrease each number in the list by 1
p(l); // And then print the list again
} // End of if
if(l.contains(0)){ // If the list now contains a 0
for(i=0;i<c;l.set(i,l.get(i++)+1)); // Increase each number in the list by 1
p(l); // And then print the list again
} // End of if
if((i=l.indexOf(13))>=0){ // If the list contains a 13 (and save it's index in `i` at the same time)
for(;i<l.size();l.remove(i)); // Remove everything from that index and onward
p(l); // And then print the list again
} // End of if
if(l.contains(2)){ // If the list now contains a 2
for(i=0;i<l.size();) // Loop over the list
if(l.get(i)%2>0) // If the current list item is odd
l.remove(l.get(i)); // Remove it
else // If it's even instead
i++; // Go to the next item
// End of loop (implicit / single-line body)
p(l); // And print the list again
} // End of if
if(l.contains(20)){ // If the list now contains a 20
p(20*(l.get(2)%2<1?1:l.size())); // Print 20 if the third item in the list is odd, or 20*size if it's even instead
return; // And then terminate the method
} // End of if
i=0; // Reset `i` to 0
for(long x:l)i+=x; // And calculate the total sum of the list (stored in `i`)
for(;i>50;) // Loop as long as this list's sum is above 50
i-=l.remove(l.size()-1); // Subtract the last item from this sum, and then remove it from the list
// End of loop (implicit / single line body)
p(l); // And print the list again
if(l.contains(16)) // If the list now contains a 16
p(Byte.valueOf(i+"",16)); // Print the sum (still stored in `i`) as hexadecimal
// End of if (implicit / single-line body)
p(i); // And print the sum as integer either way
} // End of main method
<T>void p(T t){ // Separate method with a generic parameter
System.out.println(t); // Print the given parameter including a new-line
} // End of separated method
样本输出:
不会输出样本输出后面的注释,但我将其添加为澄清。
在这里尝试。
[17, 5, 3, 1, 16, 17, 11, 7, 13] // Initial print (size 9)
[16, 4, 2, 0, 15, 16, 10, 6, 12] // Rule 1 (contains a 7)
[17, 5, 3, 1, 16, 17, 11, 7, 13] // Rule 2 (contains a 0)
[17, 5, 3, 1, 16, 17, 11, 7] // Rule 3 (contains a 13)
[17, 5, 3, 1, 16] // Rule 6 (sum must be <= 50)
66 // Rule 7 (contains a 16 -> print as Hexadecimal)
42 // Print sum as integer
[4, 18, 17, 12, 11, 8] // Initial print (size 6)
[4, 18, 17] // Rule 6 (sum must be <= 50)
39 // Print sum as integer
[4, 14, 6, 14, 7, 20, 2, 2] // Initial print (size 8)
[3, 13, 5, 13, 6, 19, 1, 1] // Rule 1 (contains a 7)
[3] // Rule 3 (contains a 13)
[3] // Print is always done after rule 6
3 // Print sum as integer