From 46a659c983911b87b38b20cd4b28ab9176e4fdb3 Mon Sep 17 00:00:00 2001
From: braxtonhall
Date: Sun, 23 Oct 2022 19:13:46 -0700
Subject: Add fib-java
---
entries/nritschel/fib-java/fib.iml | 13 +++++++++++++
.../fib-java/src/CachedFibonacciNumberFactory.java | 13 +++++++++++++
.../nritschel/fib-java/src/FibonacciCalculator.java | 3 +++
.../fib-java/src/FibonacciCalculatorImpl.java | 17 +++++++++++++++++
entries/nritschel/fib-java/src/FibonacciNumber.java | 19 +++++++++++++++++++
.../fib-java/src/FibonacciNumberFactory.java | 3 +++
entries/nritschel/fib-java/src/Main.java | 21 +++++++++++++++++++++
.../fib-java/src/NaiveFibonacciNumberFactory.java | 6 ++++++
8 files changed, 95 insertions(+)
create mode 100644 entries/nritschel/fib-java/fib.iml
create mode 100644 entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java
create mode 100644 entries/nritschel/fib-java/src/FibonacciCalculator.java
create mode 100644 entries/nritschel/fib-java/src/FibonacciCalculatorImpl.java
create mode 100644 entries/nritschel/fib-java/src/FibonacciNumber.java
create mode 100644 entries/nritschel/fib-java/src/FibonacciNumberFactory.java
create mode 100644 entries/nritschel/fib-java/src/Main.java
create mode 100644 entries/nritschel/fib-java/src/NaiveFibonacciNumberFactory.java
(limited to 'entries/nritschel')
diff --git a/entries/nritschel/fib-java/fib.iml b/entries/nritschel/fib-java/fib.iml
new file mode 100644
index 0000000..815e958
--- /dev/null
+++ b/entries/nritschel/fib-java/fib.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java b/entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java
new file mode 100644
index 0000000..5c404e8
--- /dev/null
+++ b/entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java
@@ -0,0 +1,13 @@
+import java.util.HashMap;
+
+public class CachedFibonacciNumberFactory implements FibonacciNumberFactory {
+ private final HashMap cachedNumbers = new HashMap<>();
+
+ @Override
+ public FibonacciNumber getFibonacciNumber(int num) {
+ if (!cachedNumbers.containsKey(num)) {
+ cachedNumbers.put(num, new FibonacciNumber(num));
+ }
+ return cachedNumbers.get(num);
+ }
+}
diff --git a/entries/nritschel/fib-java/src/FibonacciCalculator.java b/entries/nritschel/fib-java/src/FibonacciCalculator.java
new file mode 100644
index 0000000..8806c20
--- /dev/null
+++ b/entries/nritschel/fib-java/src/FibonacciCalculator.java
@@ -0,0 +1,3 @@
+public interface FibonacciCalculator {
+ public int calculateFibonacci(FibonacciNumber fib);
+}
diff --git a/entries/nritschel/fib-java/src/FibonacciCalculatorImpl.java b/entries/nritschel/fib-java/src/FibonacciCalculatorImpl.java
new file mode 100644
index 0000000..7bb5ee9
--- /dev/null
+++ b/entries/nritschel/fib-java/src/FibonacciCalculatorImpl.java
@@ -0,0 +1,17 @@
+public class FibonacciCalculatorImpl implements FibonacciCalculator {
+ private final FibonacciNumberFactory factory;
+
+ public FibonacciCalculatorImpl(FibonacciNumberFactory factory) {
+ this.factory = factory;
+ }
+
+ @Override
+ public int calculateFibonacci(FibonacciNumber fib) {
+ if (fib.getNumber() <= 2) {
+ return 1;
+ }
+ else {
+ return factory.getFibonacciNumber(fib.getNumber() - 1).calculate(this) + factory.getFibonacciNumber(fib.getNumber() - 2).calculate(this);
+ }
+ }
+}
diff --git a/entries/nritschel/fib-java/src/FibonacciNumber.java b/entries/nritschel/fib-java/src/FibonacciNumber.java
new file mode 100644
index 0000000..fc9381f
--- /dev/null
+++ b/entries/nritschel/fib-java/src/FibonacciNumber.java
@@ -0,0 +1,19 @@
+public class FibonacciNumber {
+ private final int number;
+ private Integer result;
+
+ public FibonacciNumber(int number) {
+ this.number = number;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public int calculate(FibonacciCalculator calculator) {
+ if (result == null) {
+ result = calculator.calculateFibonacci(this);
+ }
+ return result;
+ }
+}
diff --git a/entries/nritschel/fib-java/src/FibonacciNumberFactory.java b/entries/nritschel/fib-java/src/FibonacciNumberFactory.java
new file mode 100644
index 0000000..42ef6c2
--- /dev/null
+++ b/entries/nritschel/fib-java/src/FibonacciNumberFactory.java
@@ -0,0 +1,3 @@
+public interface FibonacciNumberFactory {
+ public FibonacciNumber getFibonacciNumber(int num);
+}
diff --git a/entries/nritschel/fib-java/src/Main.java b/entries/nritschel/fib-java/src/Main.java
new file mode 100644
index 0000000..8ae46f1
--- /dev/null
+++ b/entries/nritschel/fib-java/src/Main.java
@@ -0,0 +1,21 @@
+public class Main {
+ public static void main(String[] args) {
+ if (args.length < 1) {
+ System.out.println("""
+ Please provide:
+ 1. fibonacci number to compute, and
+ 2. (optional) the calculation method (naive or cached).""");
+ }
+ else {
+ FibonacciNumberFactory factory;
+ if (args.length >= 2 && args[1].equals("naive")) {
+ factory = new NaiveFibonacciNumberFactory();
+ }
+ else {
+ factory = new CachedFibonacciNumberFactory();
+ }
+ FibonacciCalculator calculator = new FibonacciCalculatorImpl(factory);
+ System.out.println(factory.getFibonacciNumber(Integer.parseInt(args[0])).calculate(calculator));
+ }
+ }
+}
diff --git a/entries/nritschel/fib-java/src/NaiveFibonacciNumberFactory.java b/entries/nritschel/fib-java/src/NaiveFibonacciNumberFactory.java
new file mode 100644
index 0000000..5185a8b
--- /dev/null
+++ b/entries/nritschel/fib-java/src/NaiveFibonacciNumberFactory.java
@@ -0,0 +1,6 @@
+public class NaiveFibonacciNumberFactory implements FibonacciNumberFactory {
+ @Override
+ public FibonacciNumber getFibonacciNumber(int num) {
+ return new FibonacciNumber(num);
+ }
+}
--
cgit v1.2.3-70-g09d2
From 7972ad88012a56f6afd54ada46cd45206418682a Mon Sep 17 00:00:00 2001
From: braxtonhall
Date: Mon, 24 Oct 2022 12:03:21 -0700
Subject: Add Nico's new fibs
---
entries/nritschel/assets/scratch.png | Bin 0 -> 752302 bytes
entries/nritschel/scratch/README.md | 1 +
entries/nritschel/scratch/fib.sb3 | Bin 0 -> 43364 bytes
entries/nritschel/xlsx/fib.xlsx | Bin 0 -> 11704 bytes
people.json | 8 ++++++++
5 files changed, 9 insertions(+)
create mode 100644 entries/nritschel/assets/scratch.png
create mode 100644 entries/nritschel/scratch/README.md
create mode 100644 entries/nritschel/scratch/fib.sb3
create mode 100644 entries/nritschel/xlsx/fib.xlsx
(limited to 'entries/nritschel')
diff --git a/entries/nritschel/assets/scratch.png b/entries/nritschel/assets/scratch.png
new file mode 100644
index 0000000..5883245
Binary files /dev/null and b/entries/nritschel/assets/scratch.png differ
diff --git a/entries/nritschel/scratch/README.md b/entries/nritschel/scratch/README.md
new file mode 100644
index 0000000..e059267
--- /dev/null
+++ b/entries/nritschel/scratch/README.md
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/entries/nritschel/scratch/fib.sb3 b/entries/nritschel/scratch/fib.sb3
new file mode 100644
index 0000000..a3cf2cc
Binary files /dev/null and b/entries/nritschel/scratch/fib.sb3 differ
diff --git a/entries/nritschel/xlsx/fib.xlsx b/entries/nritschel/xlsx/fib.xlsx
new file mode 100644
index 0000000..e1b662d
Binary files /dev/null and b/entries/nritschel/xlsx/fib.xlsx differ
diff --git a/people.json b/people.json
index 26dc1db..fa3f624 100644
--- a/people.json
+++ b/people.json
@@ -130,6 +130,14 @@
{
"name": "fib-java",
"link": "./entries/nritschel/fib-java/src"
+ },
+ {
+ "name": "xlsx",
+ "link": "./entries/nritschel/xlsx/fib.xlsx"
+ },
+ {
+ "name": "scratch",
+ "link": "./entries/nritschel/scratch"
}
]
},
--
cgit v1.2.3-70-g09d2