4 ms·
Try {2,2,1}
by ldx1024 4y ago
Try {2,2,1}
- yarg 4y agoYeah, at some point I'm going to need to accept that I'm too burnt out to code anymore.
- ldx1024 4y agoSoftware is hard, that's why we make the big bucks :)
- yarg 4y agoI never did; though even my employers acknowledged that I was undervalued - albeit as I walked out the door. I wasn't joking though - I haven't been able to work for years and have no real hope of piecing myself back together. (Mushrooms help, though they're seasonal - and there's no damned way the government's ever going to legalise them.)
- yarg 4y ago/* I used to be able to do this without a compiler */ for(;;){ int i = values[0]; if(i == values[i])return i; values[i] ^= values[0]; values[0] ^= values[i]; values[i] ^= values[0]; } /* full test code, does java really not have Arrays.shuffle? */ public static void main(String...args){ final int result; Integer[] values = new Integer[12]; for(int i = 1; i < values.length; i++){ values[i] = i; } final int dupe = values[0] = 1 + new Random().nextInt(values.length - 1); final var list = Arrays.asList(values); Collections.shuffle(list); System.err.println(list); for(;;){ int i = values[0]; if(i == values[i]){ result = i; break; } values[i] ^= values[0]; values[0] ^= values[i]; values[i] ^= values[0]; } System.err.println(dupe + " " + result); }
- ldx1024 4y agoNice!