aboutsummaryrefslogtreecommitdiff
path: root/Practical2
diff options
context:
space:
mode:
authorCamil Staps2015-12-09 23:27:53 +0000
committerCamil Staps2015-12-09 23:27:53 +0000
commit0d4180ab0a80ea854f28b7debff22548ce5974a5 (patch)
tree4daff8a177d89f93d4b6377f6e3b047ab0469be8 /Practical2
parentWorking solution Practical 2, small fixes (diff)
Removed Java Practical2; moved C to main directory
Diffstat (limited to 'Practical2')
-rw-r--r--Practical2/Makefile (renamed from Practical2/c/Makefile)0
-rw-r--r--Practical2/checkout.c (renamed from Practical2/c/checkout.c)0
-rw-r--r--Practical2/src/nl/camilstaps/cs/CheckoutHelper.java67
-rw-r--r--Practical2/src/nl/camilstaps/cs/Main.java23
-rwxr-xr-xPractical2/tester/test.sh12
5 files changed, 2 insertions, 100 deletions
diff --git a/Practical2/c/Makefile b/Practical2/Makefile
index e64a1f7..e64a1f7 100644
--- a/Practical2/c/Makefile
+++ b/Practical2/Makefile
diff --git a/Practical2/c/checkout.c b/Practical2/checkout.c
index 82eda3a..82eda3a 100644
--- a/Practical2/c/checkout.c
+++ b/Practical2/checkout.c
diff --git a/Practical2/src/nl/camilstaps/cs/CheckoutHelper.java b/Practical2/src/nl/camilstaps/cs/CheckoutHelper.java
deleted file mode 100644
index 5688cf0..0000000
--- a/Practical2/src/nl/camilstaps/cs/CheckoutHelper.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package nl.camilstaps.cs;
-
-import java.util.ArrayList;
-
-/**
- * Created by camil on 11/28/15.
- */
-class CheckoutHelper {
- private final ArrayList<Integer> products = new ArrayList<>();
- private int minimal_price;
-
- public CheckoutHelper() {
- }
-
- private static int round(int cents) throws IllegalArgumentException {
- switch (cents % 5) {
- case 0: return cents;
- case 1: return cents - 1;
- case 2: return cents - 2;
- case 3: return cents + 2;
- case 4: return cents + 1;
- }
- throw new IllegalArgumentException("Incorrect number of cents.");
- }
-
- public int minimumPayment(int dividers) {
- int minimums[][] = new int[products.size() + 1][dividers + 1];
- int last[][] = new int[products.size() + 1][dividers + 1];
- for (int p = 0; p <= products.size(); p++) {
- for (int d = 0; d <= dividers; d++) {
- if (p == 0) {
- minimums[p][d] = 0; // No products
- last[p][d] = 0;
- } else if (d == 0) {
- int sum = 0;
- for (int p2 = 0; p < products.size() && p2 < p; p2++)
- sum += products.get(p2);
- minimums[p][d] = round(sum); // no dividers
- last[p][d] = sum;
- } else {
- int try1 = minimums[p-1][d] - round(last[p-1][d]) + round(last[p-1][d] + products.get(p-1)); // don't place a divider
- int try2 = minimums[p-1][d-1] + round(products.get(p-1)); // place a divider
- if (try1 < try2) {
- minimums[p][d] = try1;
- last[p][d] = last[p-1][d] + products.get(p-1);
- } else {
- minimums[p][d] = try2;
- last[p][d] = products.get(p-1);
- }
- }
- }
- }
-
- return minimal_price + minimums[products.size()][dividers];
- }
-
- public void addProduct(int price) {
- int has_to_pay = (price / 5) * 5;
- int rest = price % 5;
-
- minimal_price += has_to_pay;
- if (rest != 0) {
- products.add(rest);
- }
- }
-
-}
diff --git a/Practical2/src/nl/camilstaps/cs/Main.java b/Practical2/src/nl/camilstaps/cs/Main.java
deleted file mode 100644
index 2009c4d..0000000
--- a/Practical2/src/nl/camilstaps/cs/Main.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package nl.camilstaps.cs;
-
-import java.util.Scanner;
-
-public class Main {
-
- public static void main(String[] args) {
- CheckoutHelper ch = new CheckoutHelper();
- int n_dividers = readCheckoutHelper(new Scanner(System.in), ch);
- System.out.println(ch.minimumPayment(n_dividers));
- }
-
- private static int readCheckoutHelper(Scanner sc, CheckoutHelper ch) {
- int n_products = sc.nextInt();
- int n_dividers = sc.nextInt();
-
- for (int i = 0; i < n_products; i++)
- ch.addProduct(sc.nextInt());
-
- return n_dividers;
- }
-
-}
diff --git a/Practical2/tester/test.sh b/Practical2/tester/test.sh
index 4a982ac..9051e97 100755
--- a/Practical2/tester/test.sh
+++ b/Practical2/tester/test.sh
@@ -1,14 +1,6 @@
#!/bin/bash
-java="/usr/lib/jvm/java-8-openjdk-amd64/bin/java"
-
-# Java
-#dir="$(dirname $0)/../out/production/Practical2"
-#samples="../../../tester/samples"
-#cmd="$java nl.camilstaps.cs.Main"
-
-# C
-dir="$(dirname $0)/../c"
-samples="../tester/samples"
+dir="$(dirname $0)/.."
+samples="./tester/samples"
cmd="./checkout"
failed=0