Skip to content

Commit 391a009

Browse files
committed
markdown source builds
Auto-generated via `{sandpaper}` Source : 8ace359 Branch : main Author : Tim Dennis <tdennis@library.ucla.edu> Time : 2026-01-22 01:53:05 +0000 Message : Merge pull request #32 from LibraryCarpentry/fix/exercise-content Fix exercise structure and add Library Sort challenge
1 parent e4236f9 commit 391a009

File tree

4 files changed

+1156
-3
lines changed

4 files changed

+1156
-3
lines changed

config.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#------------------------------------------------------------
2+
# Values for this lesson.
3+
#------------------------------------------------------------
4+
5+
# Which carpentry is this (swc, dc, lc, or cp)?
6+
# swc: Software Carpentry
7+
# dc: Data Carpentry
8+
# lc: Library Carpentry
9+
# cp: Carpentries (to use for instructor training for instance)
10+
# incubator: The Carpentries Incubator
11+
carpentry: 'lc'
12+
13+
# Overall title for pages.
14+
title: 'Introducing Computational Thinking'
15+
16+
# Date the lesson was created (YYYY-MM-DD, this is empty by default)
17+
created: "2022-08-12"
18+
19+
# Comma-separated list of keywords for the lesson
20+
keywords: 'software, data, lesson, The Carpentries'
21+
22+
# Life cycle stage of the lesson
23+
# possible values: pre-alpha, alpha, beta, stable
24+
life_cycle: 'alpha'
25+
26+
# License of the lesson materials (recommended CC-BY 4.0)
27+
license: 'CC-BY 4.0'
28+
29+
# Link to the source repository for this lesson
30+
source: 'https://github.com/LibraryCarpentry/lc-computational-thinking/'
31+
32+
# Default branch of your lesson
33+
branch: 'main'
34+
35+
# Who to contact if there are any issues
36+
contact: 'team@carpentries.org'
37+
38+
# Navigation ------------------------------------------------
39+
#
40+
# Use the following menu items to specify the order of
41+
# individual pages in each dropdown section. Leave blank to
42+
# include all pages in the folder.
43+
#
44+
# Example -------------
45+
#
46+
# episodes:
47+
# - introduction.md
48+
# - first-steps.md
49+
#
50+
# learners:
51+
# - setup.md
52+
#
53+
# instructors:
54+
# - instructor-notes.md
55+
#
56+
# profiles:
57+
# - one-learner.md
58+
# - another-learner.md
59+
60+
# Order of episodes in your lesson
61+
episodes:
62+
- intro.md
63+
- exercise.md
64+
- computation_practice.md
65+
- computation_programming.md
66+
- pseudocode.md
67+
- solutions.Rmd
68+
69+
70+
# Information for Learners
71+
learners:
72+
73+
# Information for Instructors
74+
instructors:
75+
76+
# Learner Profiles
77+
profiles:
78+
79+
# Customisation ---------------------------------------------
80+
#
81+
# This space below is where custom yaml items (e.g. pinning
82+
# sandpaper and varnish versions) should live
83+
84+
url: 'https://library-carpentry.org/lc-computational-thinking'
85+
analytics: carpentries
86+
lang: en
87+
88+
89+

exercise.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ teaching: 25
44
exercises: 20
55
---
66

7+
::::::::::::::::::::::::::::::::::::::: objectives
8+
9+
- Apply decomposition, pattern recognition, and algorithms to both mathematical and real-world problems.
10+
- Understand how abstraction allows us to create reusable formulas and processes.
11+
- Learn the "Library Sort" algorithm as an application of computational thinking.
12+
13+
::::::::::::::::::::::::::::::::::::::::::::::::::
14+
15+
:::::::::::::::::::::::::::::::::::::::: questions
16+
17+
- How can we use computational thinking to solve complex manual tasks?
18+
- What is "Library Sort" and how does it optimize shelving?
19+
- Can the same computational strategies apply to both math and physical organization?
20+
21+
::::::::::::::::::::::::::::::::::::::::::::::::::
22+
723
In this exercise, we will see how computational thinking can be used to add up all the numbers between 1 and 200 in our heads, i.e. `1 + 2 + 3 + 4` and so on. We should be able to do this in less than a minute.
824

925
Seems impossible?
@@ -84,15 +100,94 @@ That's it! Using those four key steps, we have learned the basics of computation
84100

85101
::::::::::::::::::::::::::::::::: challenge
86102

87-
## Practice
103+
## Option 1: Practice with Numbers
88104

89105
Use the algorithm above to add up all the numbers between 1 and 24, 1 and 50, and 1 and 1,000.
90106

107+
:::::::: solution
108+
109+
**1 to 24:**
110+
- x = 24
111+
- (24 / 2) * (24 + 1)
112+
- 12 * 25 = **300**
113+
114+
**1 to 50:**
115+
- x = 50
116+
- (50 / 2) * (50 + 1)
117+
- 25 * 51 = **1,275**
118+
119+
**1 to 1,000:**
120+
- x = 1000
121+
- (1000 / 2) * (1000 + 1)
122+
- 500 * 1001 = **500,500**
123+
124+
::::::::::::::::
125+
91126
::::::::::::::
92127

93128
::::::::::::::::::::::::::::::::: discussion
94129

95-
## Discussion
130+
## Discussion: Odd Numbers
96131

97132
The numbers above are all even numbers. What would be the process for adding up numbers if the final number is an odd one, e.g., 17? Can you use the same formula? If not, what adaptations would you need to make to the formula?
133+
134+
:::::::: solution
135+
136+
Yes, the formula `(x/2) * (x + 1)` still works mathematically.
137+
138+
**For 17:**
139+
- x = 17
140+
- (17 / 2) * (17 + 1)
141+
- 8.5 * 18 = **153**
142+
143+
**Conceptually:**
144+
If you prefer the "pairing" method (Decomposition):
145+
- You have 8 pairs (1+17, 2+16, etc.) that sum to 18.
146+
- The middle number, 9, is left over.
147+
- (8 * 18) + 9 = 144 + 9 = **153**.
148+
149+
Both methods yield the same result. The abstraction formula handles the "half pair" (0.5) correctly.
150+
151+
::::::::::::::::
152+
98153
:::
154+
155+
::::::::::::::::::::::::::::::::: challenge
156+
157+
## Option 2: Shelving Books Efficiently
158+
159+
Imagine you are working in a library. You have a cart of new books that need to be shelved. The shelves are currently quite full. Every time you find the correct spot for a new book (e.g., by call number), you have to shift all the subsequent books on that shelf to the right to make space. This physical shifting is heavy, slow, and tedious.
160+
161+
How can you use **Computational Thinking** to solve this problem for future shelving? Apply the four steps:
162+
163+
1. **Decomposition:** What are the individual actions involved in shelving?
164+
2. **Pattern Recognition:** What is the specific bottleneck that repeats?
165+
3. **Abstraction:** Can we conceptually change how the shelf "works"?
166+
4. **Algorithm:** What new process can we adopt to minimize the work?
167+
168+
*Hint: Think about "Gapped Insertion Sort" or "Library Sort".*
169+
170+
:::::::: solution
171+
172+
1. **Decomposition:** Shelving involves three main actions: (a) Finding the correct spot, (b) Making space (shifting existing books), and (c) Placing the new book.
173+
2. **Pattern Recognition:** The "Making space" step is the bottleneck. It requires physical effort and time, and it happens *every single time* we insert a book into a contiguous row. The more books on the shelf, the more work it takes to shift them.
174+
3. **Abstraction:** Instead of viewing the shelf as a solid block of books that must be packed tightly, view it as a collection of items with *buffers* or *gaps* distributed between them. The "concept" of the shelf now includes empty space as a feature, not a bug.
175+
4. **Algorithm (The Library Sort):**
176+
* **Step 1 (Setup):** Spread the existing books out on the shelves so there are intentional gaps between them (e.g., leave 25% of the shelf empty).
177+
* **Step 2 (Insert):** When a new book arrives, place it into the open gap at its correct location. **No shifting is required!**
178+
* **Step 3 (Maintenance):** If a specific gap fills up completely, redistribute just the books in that small section to create new gaps.
179+
180+
By using this algorithm, you trade a small amount of space (the gaps) for a massive gain in speed and reduced effort. In computer science, this is known as a **Gapped Insertion Sort**.
181+
182+
::::::::::::::::
183+
184+
::::::::::::::
185+
186+
:::::::::::::::::::::::::::::::::::::::: keypoints
187+
188+
- Computational thinking helps us calculate sums efficiently without adding every number sequentially.
189+
- Decomposition reveals patterns (pairing numbers).
190+
- Algorithms provide a reproducible process.
191+
- Abstraction creates a formula reusable for any set of numbers.
192+
193+
::::::::::::::::::::::::::::::::::::::::::::::::::

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"index.md" "bd2d349d4978ed3c68bb2b301a671bdc" "site/built/index.md" "2026-01-22"
77
"search.md" "2d215d6e5c915ce30f5a5072d986609f" "site/built/search.md" "2026-01-22"
88
"episodes/intro.md" "e176eef6a3acadfca8817bf38d46bb9f" "site/built/intro.md" "2026-01-22"
9-
"episodes/exercise.md" "10bf563535affd64b9d8e9c283ff8c53" "site/built/exercise.md" "2026-01-22"
9+
"episodes/exercise.md" "a2aa30d792c70d1cf39f740a85e108c5" "site/built/exercise.md" "2026-01-22"
1010
"episodes/computation_practice.md" "ddb122e2e242e1587011dea9aba364fb" "site/built/computation_practice.md" "2026-01-22"
1111
"episodes/computation_programming.md" "7e69751fdb0fc9d7d74fb641ae898f0a" "site/built/computation_programming.md" "2026-01-22"
1212
"episodes/pseudocode.md" "0ea2e3e7d977ad7245d0df4868503439" "site/built/pseudocode.md" "2026-01-22"

0 commit comments

Comments
 (0)