News for hackers. Stuff that matters.
Re:Is the room open? by mothsonasloth on Monday February 10, 2020 @11:53AM (#22290810)
Behold my enterprisey Java solution

public static void main2(String[] args) {

        final List<String> rooms = new ArrayList<>(Collections.nCopies(MAX_ROOM, "CLOSED"));
        int employee = 1;

        do {
            int roomIndex = employee - 1;
            do {
                final String roomState = rooms.get(roomIndex);

                if (roomState.equals(OPEN)) {
                    rooms.set(roomIndex, CLOSED);
                } else if (roomState.equals(CLOSED)) {
                    rooms.set(roomIndex, OPEN);
                }
                roomIndex = roomIndex + employee;
            } while (roomIndex < MAX_ROOM);
            employee++;
        } while (employee <= MAX_ROOM);

        for (int i = 0; i < rooms.size(); i++) {
            if (rooms.get(i).equals(OPEN)) {
                System.out.println("Room " + (i + 1) + " is OPEN");
            }
        }
    }

There are no comments on this comment yet.