Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,17 @@
class HundredDoors {
public static void main(String[] args) {
boolean[] doors = new boolean[101];
for (int i = 1; i < doors.length; i++) {
for (int j = i; j < doors.length; j += i) {
doors[j] = !doors[j];
}
}
for (int i = 1; i < doors.length; i++) {
if (doors[i]) {
System.out.printf("Door %d is open.%n", i);
}
}
}
}

View file

@ -0,0 +1,14 @@
import java.util.BitSet;
public class HundredDoors {
public static void main(String[] args) {
final int n = 100;
var a = new BitSet(n);
for (int i = 1; i <= n; i++) {
for (int j = i - 1; j < n; j += i) {
a.flip(j);
}
}
a.stream().map(i -> i + 1).forEachOrdered(System.out::println);
}
}

View file

@ -0,0 +1,6 @@
class HundredDoors {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++)
System.out.printf("Door %d is open.%n", i * i);
}
}

View file

@ -0,0 +1,12 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class HundredDoors {
public static void main(String args[]) {
String openDoors = IntStream.rangeClosed(1, 100)
.filter(i -> Math.pow((int) Math.sqrt(i), 2) == i)
.mapToObj(Integer::toString)
.collect(Collectors.joining(", "));
System.out.printf("Open doors: %s%n", openDoors);
}
}