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,29 @@
public class FizzBuzz {
public static void main(String[] args) {
Sound[] sounds = {new Sound(3, "Fizz"), new Sound(5, "Buzz"), new Sound(7, "Baxx")};
for (int i = 1; i <= 20; i++) {
StringBuilder sb = new StringBuilder();
for (Sound sound : sounds) {
sb.append(sound.generate(i));
}
System.out.println(sb.length() == 0 ? i : sb.toString());
}
}
private static class Sound {
private final int trigger;
private final String onomatopoeia;
public Sound(int trigger, String onomatopoeia) {
this.trigger = trigger;
this.onomatopoeia = onomatopoeia;
}
public String generate(int i) {
return i % trigger == 0 ? onomatopoeia : "";
}
}
}

View file

@ -0,0 +1,29 @@
import java.util.stream.*;
import java.util.function.*;
import java.util.*;
public class fizzbuzz_general {
/**
* To run: java fizzbuzz_general.java 3=Fizz 5=Buzz 7=Baxx 100
*
*/
public static void main(String[] args) {
Function<String[],Function<Integer,String>> make_cycle_function =
parts -> j -> j%(Integer.parseInt(parts[0]))==0?parts[1]:"";
List<Function<Integer,String>> cycle_functions = Stream.of(args)
.map(arg -> arg.split("="))
.filter(parts->parts.length==2)
.map(make_cycle_function::apply)
.collect(Collectors.toList());
Function<Integer,String> moduloTesters = i -> cycle_functions.stream()
.map(fcn->fcn.apply(i))
.collect(Collectors.joining());
BiFunction<Integer,String,String> formatter =
(i,printThis) -> "".equals(printThis)?Integer.toString(i):printThis;
Function<Integer,String> fizzBuzz = i -> formatter.apply(i,moduloTesters.apply(i));
IntStream.rangeClosed(0,Integer.parseInt(args[args.length-1]))
.mapToObj(Integer::valueOf)
.map(fizzBuzz::apply)
.forEach(System.out::println);
}
}