From 0500a13ae6da4ef4be05616b6c8d5719a180281e Mon Sep 17 00:00:00 2001 From: Tong-Kiat Tan <2617095+tongkiat@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:27:41 +0800 Subject: [PATCH 1/7] Add sublist/README.md --- exercises/sublist/README.md | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 exercises/sublist/README.md diff --git a/exercises/sublist/README.md b/exercises/sublist/README.md new file mode 100644 index 00000000..6a6a37e7 --- /dev/null +++ b/exercises/sublist/README.md @@ -0,0 +1,46 @@ +# Sublist + +Given two lists determine if the first list is contained within the second +list, if the second list is contained within the first list, if both lists are +contained within each other or if none of these are true. + +Specifically, a list A is a sublist of list B if by dropping 0 or more elements +from the front of B and 0 or more elements from the back of B you get a list +that's completely equal to A. + +Examples: + + * A = [1, 2, 3], B = [1, 2, 3, 4, 5], A is a sublist of B + * A = [3, 4, 5], B = [1, 2, 3, 4, 5], A is a sublist of B + * A = [3, 4], B = [1, 2, 3, 4, 5], A is a sublist of B + * A = [1, 2, 3], B = [1, 2, 3], A is equal to B + * A = [1, 2, 3, 4, 5], B = [2, 3, 4], A is a superlist of B + * A = [1, 2, 4], B = [1, 2, 3, 4, 5], A is not a superlist of, sublist of or equal to B + +## Running and testing your solutions + +### From the command line + +NB: Unlike other exercises in this track, the tests for this exercise *only* +work with __GNU Guile__ (not Chez Scheme). + +Simply execute, + +```sh +$ guile test.scm +``` + +By default, only the first test is executed when you run the command. This is +intentional, as it allows you to focus on just making that one test pass. Once +it passes, you can enable the next test(s) by removing or commenting out +`(test-skip ...)`. When all tests have been enabled and your implementation +makes them all pass, you'll have solved the exercise! + +### Failed Test Cases + +If some of the test cases fail, you should be able to check the actual input +and the expected output from the log file (`sublist.log`). + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have +completed the exercise. From ec2185dad7ebf034325ecf91f67ffc369e80ad17 Mon Sep 17 00:00:00 2001 From: Tong-Kiat Tan <2617095+tongkiat@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:27:58 +0800 Subject: [PATCH 2/7] Add sublist/test.scm --- exercises/sublist/test.scm | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 exercises/sublist/test.scm diff --git a/exercises/sublist/test.scm b/exercises/sublist/test.scm new file mode 100644 index 00000000..e80ee86d --- /dev/null +++ b/exercises/sublist/test.scm @@ -0,0 +1,92 @@ +(load "sublist.scm") + +(use-modules (srfi srfi-64)) + +(test-begin "sublist") + +; (test-skip "empty lists") +(test-eq "empty lists" + (sublist '() '()) + 'equal) + +(test-skip "empty list within non-empty list") +(test-eq "empty list within non-empty list" + (sublist '() '(1 2 3)) + 'sublist) + +(test-skip "non empty list contains empty list") +(test-eq "non empty list contains empty list" + (sublist '(1 2 3) '()) + 'superlist) + +(test-skip "list equals itself") +(test-eq "list equals itself" + (sublist '(1 2 3) '(1 2 3)) + 'equal) + +(test-skip "different lists") +(test-eq "different lists" + (sublist '(1 2 3) '(2 3 4)) + 'unequal) + +(test-skip "false start") +(test-eq "false start" + (sublist '(1 2 5) '(0 1 2 3 1 2 5 6)) + 'sublist) + +(test-skip "consecutive") +(test-eq "consecutive" + (sublist '(1 1 2) '(0 1 1 1 2 1 2)) + 'sublist) + +(test-skip "sublist at start") +(test-eq "sublist at start" + (sublist '(0 1 2) '(0 1 2 3 4 5)) + 'sublist) + +(test-skip "sublist in middle") +(test-eq "sublist in middle" + (sublist '(2 3 4) '(0 1 2 3 4 5)) + 'sublist) + +(test-skip "sublist at end") +(test-eq "sublist at end" + (sublist '(3 4 5) '(0 1 2 3 4 5)) + 'sublist) + +(test-skip "at start of superlist") +(test-eq "at start of superlist" + (sublist '(0 1 2 3 4 5) '(0 1 2)) + 'superlist) + +(test-skip "in middle of superlist") +(test-eq "in middle of superlist" + (sublist '(0 1 2 3 4 5) '(2 3)) + 'superlist) + +(test-skip "at end of superlist") +(test-eq "at end of superlist" + (sublist '(0 1 2 3 4 5) '(3 4 5)) + 'superlist) + +(test-skip "first list missing elements from second list") +(test-eq "first list missing elements from second list" + (sublist '(1 3) '(1 2 3)) + 'unequal) + +(test-skip "second list missing element from first list") +(test-eq "second list missing element from first list" + (sublist '(1 2 3) '(1 3)) + 'unequal) + +(test-skip "order matters to a list") +(test-eq "order matters to a list" + (sublist '(1 2 3) '(3 2 1)) + 'unequal) + +(test-skip "same digits different numbers") +(test-eq "same digits different numbers" + (sublist '(1 0 1) '(10 1)) + 'unequal) + +(test-end "sublist") From 29571ab007f55f5c447cb066fa201b678c951f09 Mon Sep 17 00:00:00 2001 From: Tong-Kiat Tan <2617095+tongkiat@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:28:23 +0800 Subject: [PATCH 3/7] Add sublist/example.scm --- exercises/sublist/example.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 exercises/sublist/example.scm diff --git a/exercises/sublist/example.scm b/exercises/sublist/example.scm new file mode 100644 index 00000000..776a1425 --- /dev/null +++ b/exercises/sublist/example.scm @@ -0,0 +1,22 @@ +(define (is-prefix-of? xs ys) + (cond + [(null? xs) #t] + [(null? ys) #f] + [(equal? (car xs) (car ys)) (is-prefix-of? (cdr xs) (cdr ys))] + [else #f])) + +(define (sublist-of? xs ys) + (if (and (not (null? xs)) + (null? ys)) + #f + (or (is-prefix-of? xs ys) + (sublist-of? xs (cdr ys))))) + +(define (sublist xs ys) + (let ([sub (sublist-of? xs ys)] + [super (sublist-of? ys xs)]) + (cond + [(and sub super) 'equal] + [sub 'sublist] + [super 'superlist] + [else 'unequal]))) From b50be5a087f519e85c7c0d307f1593bf111ef3af Mon Sep 17 00:00:00 2001 From: Tong-Kiat Tan <2617095+tongkiat@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:28:46 +0800 Subject: [PATCH 4/7] Add sublist/sublist.scm --- exercises/sublist/sublist.scm | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 exercises/sublist/sublist.scm diff --git a/exercises/sublist/sublist.scm b/exercises/sublist/sublist.scm new file mode 100644 index 00000000..5febd69a --- /dev/null +++ b/exercises/sublist/sublist.scm @@ -0,0 +1,4 @@ +(import (rnrs)) + +(define (sublist xs ys) + 'implement-me!) From 0f3e2fbcd2ffef7e3fbb861e2d255892047078b7 Mon Sep 17 00:00:00 2001 From: Tong-Kiat Tan <2617095+tongkiat@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:29:05 +0800 Subject: [PATCH 5/7] Add sublist/.meta/version --- exercises/sublist/.meta/version | 1 + 1 file changed, 1 insertion(+) create mode 100644 exercises/sublist/.meta/version diff --git a/exercises/sublist/.meta/version b/exercises/sublist/.meta/version new file mode 100644 index 00000000..9084fa2f --- /dev/null +++ b/exercises/sublist/.meta/version @@ -0,0 +1 @@ +1.1.0 From 618a024197ee2d7241e11eb78b58999465a60e6c Mon Sep 17 00:00:00 2001 From: Tong-Kiat Tan <2617095+tongkiat@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:36:12 +0800 Subject: [PATCH 6/7] Update config/track.ss --- config/track.ss | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/track.ss b/config/track.ss index 3e3b0be5..1ccbace6 100644 --- a/config/track.ss +++ b/config/track.ss @@ -308,4 +308,11 @@ (difficulty . 2) (topics conditionals string loop math)) + ((slug . sublist) + (uuid . "ac954921-31e4-4c8d-8125-9d44a8c1baba") + (core . #f) + (unlocked-by) + (difficulty . 2) + (topics list)) + ) From 3ff6e2400de99b1ba75d053f17a4dd64205bc78a Mon Sep 17 00:00:00 2001 From: Guy Gastineau Date: Thu, 9 Jun 2022 15:59:33 -0400 Subject: [PATCH 7/7] Update config.json --- config.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config.json b/config.json index 59fd504c..0dd4cdce 100644 --- a/config.json +++ b/config.json @@ -516,6 +516,16 @@ "math", "vector" ] + }, + { + "slug": "sublist", + "uuid": "ac954921-31e4-4c8d-8125-9d44a8c1baba", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "list" + ] } ] },