From 1c8dde74f6fe9bccb859dce4161a052d848739da Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Fri, 9 Jun 2023 11:13:08 -0700 Subject: [PATCH 01/31] Hack pavement.py as instructed. --- pavement.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pavement.py b/pavement.py index 8f122aab..c8d530e3 100644 --- a/pavement.py +++ b/pavement.py @@ -79,6 +79,24 @@ ) ) +template_args = { + 'course_id': 'csawesome', + 'login_required':'false', + 'appname':master_app, + 'loglevel': 10, + 'course_url':master_url, + 'use_services': 'true', + 'python3': 'false', + 'dburl': 'postgresql://runestone@localhost/runestone', + 'basecourse': 'csawesome', + # new 7/2019 changes + 'dynamic_pages': dynamic_pages, + 'downloads_enabled': 'false', + 'enable_chatcodes': 'false', + 'allow_pairs': 'false', + 'default_ac_lang': 'java', +} + version = pkg_resources.require("runestone")[0].version options.build.template_args['runestone_version'] = version From fff3dce2e4135fcbf83e0057e1ee29527db45efc Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Fri, 9 Jun 2023 11:13:37 -0700 Subject: [PATCH 02/31] Script to fix up some entities in embedded HTML --- fix-entities.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 fix-entities.pl diff --git a/fix-entities.pl b/fix-entities.pl new file mode 100755 index 00000000..c8451968 --- /dev/null +++ b/fix-entities.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +use warnings; +use strict; + +$^I = '.bak'; + +while (<>) { + if (/^\s+:feedback/) { + # Unescape any that are actually escaped. + s/&/&/g; + s/</ Date: Fri, 9 Jun 2023 11:27:28 -0700 Subject: [PATCH 03/31] Improve entity fixer. --- fix-entities.pl | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/fix-entities.pl b/fix-entities.pl index c8451968..7a1d40b3 100755 --- a/fix-entities.pl +++ b/fix-entities.pl @@ -3,17 +3,31 @@ use warnings; use strict; -$^I = '.bak'; +my $OPEN_LT = "TAG_PLACEHOLDER_SHOULD_NOT_EXIST_IN_FEEDBACK"; + +$^I = ''; while (<>) { - if (/^\s+:feedback/) { - # Unescape any that are actually escaped. - s/&/&/g; - s/</)/$OPEN_LT/g; + + # unescape any that are actually escaped. + s/&/&/g; + s/</ Date: Fri, 9 Jun 2023 13:35:32 -0700 Subject: [PATCH 04/31] More work on cleaning rst. --- Makefile | 25 +++++++++++++++++++++++++ fix-entities.pl => fix.pl | 8 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Makefile rename fix-entities.pl => fix.pl (75%) diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..64b60b47 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +R2P := ~/3rdparty/Runestone2PreTeXt + +xml := $(shell find build/xml -type f) +ptx := $(patsubst build/xml/%.xml,pretext/%.ptx,$(xml)) + +all: + @echo $(ptx) + +fix: + find _sources/ -name '*.rst' -exec ./fix.pl {} \; + +xml: fix + runestone rs2ptx + +pretext/%.ptx: build/xml/%.xml | pretext + xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@ + +ptx: $(ptx) + +pretext: + mkdir $@ + +clean: + rm -rf pretext + rm -rf build/xml diff --git a/fix-entities.pl b/fix.pl similarity index 75% rename from fix-entities.pl rename to fix.pl index 7a1d40b3..9d7e1aaa 100755 --- a/fix-entities.pl +++ b/fix.pl @@ -8,12 +8,15 @@ $^I = ''; while (<>) { - if (/^\s+:feedback/) { + if (/^\s+:(feedback|answer)/) { if (/$OPEN_LT/) { die "$OPEN_LT occured!"; } + # Fix some broken close tags. + s/(<\/\w+)\b(?!>)/$1>/g; + # Swap out <'s in actual embedded tags. s/<(?=\/?\w+>)/$OPEN_LT/g; @@ -28,6 +31,9 @@ # Put back the tag <'s. s/$OPEN_LT/ tags to be XMLish. + s/
//g; + } print; } From 17a664ea6576bf1265ee232725048bd46d878f1b Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Fri, 9 Jun 2023 13:59:04 -0700 Subject: [PATCH 05/31] Make directory for ptx --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 64b60b47..b65e5053 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ xml: fix runestone rs2ptx pretext/%.ptx: build/xml/%.xml | pretext + mkdir -p $(dir $@) xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@ ptx: $(ptx) From 71ea40faec3a0d955eed248620fa67e415921799 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Fri, 9 Jun 2023 14:53:19 -0700 Subject: [PATCH 06/31] Seems like :endclick: needs to be on same line --- _sources/Unit7-ArrayList/2019delimitersQ3a.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/_sources/Unit7-ArrayList/2019delimitersQ3a.rst b/_sources/Unit7-ArrayList/2019delimitersQ3a.rst index bb6b6b48..cd2d6f20 100644 --- a/_sources/Unit7-ArrayList/2019delimitersQ3a.rst +++ b/_sources/Unit7-ArrayList/2019delimitersQ3a.rst @@ -64,9 +64,9 @@ There are problems in this section that can help you check your understanding of :optional: :click-incorrect:A string:endclick::click-incorrect: containing text and possibly delimiters has been split into *tokens* and stored inTest2:endclick: - :click-correct:String[] tokens:endclick:. :click-incorrect:Each token is either an open delimiter, a close delimiter, or a substring that is not a - delimiter:endclick:. :click-incorrect: You will write the method :endclick::click-incorrect:getDelimitersList:endclick:, :click-incorrect: which returns an:endclick: :click-correct:ArrayList:endclick::click-incorrect: - containing all the open and close delimiters found in tokens in their original order.:endclick: + :click-correct:String[] tokens:endclick:. :click-incorrect:Each token is either an open delimiter, a close delimiter, or a substring that is not a delimiter:endclick:. + :click-incorrect: You will write the method :endclick::click-incorrect:getDelimitersList:endclick:, :click-incorrect: which returns an:endclick: :click-correct:ArrayList:endclick: + :click-incorrect:containing all the open and close delimiters found in tokens in their original order.:endclick: .. reveal:: delim_cu_r2 @@ -241,7 +241,7 @@ containing all the open and close delimiters found in ``tokens`` in their origin .. activecode:: frq2019Q3A-delim :language: java - :autograde: unittest + :autograde: unittest Write the method getDelimitersList in the code below. The main method contains code to test your solution. ~~~~ From 7838deccaaa1746d5e06168bbdd4c8e9d6ba7a90 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Fri, 9 Jun 2023 15:16:41 -0700 Subject: [PATCH 07/31] Make some fixes directly on generic XML --- Makefile | 5 ++++- fix-xml.pl | 29 +++++++++++++++++++++++++++++ fix.pl | 10 ++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 fix-xml.pl diff --git a/Makefile b/Makefile index b65e5053..816678c7 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,12 @@ all: fix: find _sources/ -name '*.rst' -exec ./fix.pl {} \; -xml: fix +xml: runestone rs2ptx +fix_xml: + find build/xml -name '*.xml' -exec ./fix-xml.pl {} \; + pretext/%.ptx: build/xml/%.xml | pretext mkdir -p $(dir $@) xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@ diff --git a/fix-xml.pl b/fix-xml.pl new file mode 100755 index 00000000..ddc1cb7e --- /dev/null +++ b/fix-xml.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl + +use warnings; +use strict; + +$^I = ''; + +while (<>) { + + s/ArrayList<([A-Z])/ArrayList<$1/g; + s/ArrayList<(int)>/ArrayList<$1>/g; + s/ArrayList<>/ArrayList<>/g; + + s/ <( |=)/ <$1/g; + s/len<=/len<=/g; + s/ &&( |$)/ &&$1/g; + s/ & / & /g; + s/"&&"/"&&"/g; + s/\b([A-Z]\w+)<([A-Z]\w+)>/$1<$2>/g; + s/data-optional=true/data-optional="true"/g; + s/'data-optional="true"'/'data-optional=true'/g; + s/&&<\/cline>/&&<\/cline>/g; + s/"<(\/?(sup|q))>"/"<$1>"/g; + s{\[, , \]}{[<q>, </q>, </q>]}g; + s/i <"/i <"/g; + s/") { + + # Some blocks start with .. .. which seems to get translated to a comment + # but if the block then contains --- that's not something that can appear in + # an XML comment. + s/^\.\. \.\./../; + + #if (/<\w+\s+.*?[-a-z]+=(?!['"])/) { + # die "$_"; + #} + if (/^\s+:(feedback|answer)/) { if (/$OPEN_LT/) { From 4b600ea88462b7e034147b9c624fafd893c19bb4 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Fri, 9 Jun 2023 17:55:50 -0700 Subject: [PATCH 08/31] Run runestone from virtual env. --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 816678c7..96412528 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ R2P := ~/3rdparty/Runestone2PreTeXt xml := $(shell find build/xml -type f) ptx := $(patsubst build/xml/%.xml,pretext/%.ptx,$(xml)) +# This will run from a virtual env. +rs2ptx := python -m runestone rs2ptx + all: @echo $(ptx) @@ -10,7 +13,7 @@ fix: find _sources/ -name '*.rst' -exec ./fix.pl {} \; xml: - runestone rs2ptx + $(rs2ptx) fix_xml: find build/xml -name '*.xml' -exec ./fix-xml.pl {} \; From b7adccd2c07a917fec3e112144731b1dcdd6ea60 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 09:33:39 -0700 Subject: [PATCH 09/31] Make pages have only one top-level section for XML conversion. --- _sources/Unit8-2DArray/a2dHardMC.rst | 2 +- _sources/Unit8-2DArray/topic-8-1-2D-arrays-Day1.rst | 2 +- _sources/Unit8-2DArray/topic-8-1-2D-arrays-Day2.rst | 4 ++-- _sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day1.rst | 2 +- _sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day2.rst | 2 +- _sources/Unit9-Inheritance/topic-9-1-inheritance-day1.rst | 4 ++-- _sources/Unit9-Inheritance/topic-9-1-inheritance-day2.rst | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/_sources/Unit8-2DArray/a2dHardMC.rst b/_sources/Unit8-2DArray/a2dHardMC.rst index 56da1796..da79e28f 100644 --- a/_sources/Unit8-2DArray/a2dHardMC.rst +++ b/_sources/Unit8-2DArray/a2dHardMC.rst @@ -3,7 +3,7 @@ :start: 7 Hard Multiple Choice Questions ----------------------------------- +============================== These problems are harder than those that you will typically see on the AP CS A exam. diff --git a/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day1.rst b/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day1.rst index bf64883c..fa81a1ad 100644 --- a/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day1.rst +++ b/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day1.rst @@ -24,7 +24,7 @@ :align: right 2D Arrays (Day 1) ------------------ +================= .. index:: single: 2D Arrays diff --git a/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day2.rst b/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day2.rst index 7b7f6850..0faa1dc7 100644 --- a/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day2.rst +++ b/_sources/Unit8-2DArray/topic-8-1-2D-arrays-Day2.rst @@ -24,7 +24,7 @@ :align: right Set Value(s) in a 2D Array (Day 2) ----------------------------------------- +================================== .. index:: pair: 2D Array; initialization @@ -444,4 +444,4 @@ Try the game below to practice 2D Arrays. Click on **Arrays** and then check on .. raw:: html - \ No newline at end of file + diff --git a/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day1.rst b/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day1.rst index 37996487..25983e6d 100644 --- a/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day1.rst +++ b/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day1.rst @@ -24,7 +24,7 @@ :align: right Nested Loops for 2D Arrays (Day 1) ------------------------------------ +================================== In this lesson, you will learn how to use nested loops to traverse a 2D Array. diff --git a/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day2.rst b/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day2.rst index f3cd1636..12ec7a78 100644 --- a/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day2.rst +++ b/_sources/Unit8-2DArray/topic-8-2-2D-array-loops-Day2.rst @@ -24,7 +24,7 @@ :align: right Enhanced For-Each Loop for 2D Arrays (Day 2) ----------------------------------------------------- +============================================ .. index:: pair: 2D Array; for-each loop diff --git a/_sources/Unit9-Inheritance/topic-9-1-inheritance-day1.rst b/_sources/Unit9-Inheritance/topic-9-1-inheritance-day1.rst index 68bdbe68..53ba61a0 100644 --- a/_sources/Unit9-Inheritance/topic-9-1-inheritance-day1.rst +++ b/_sources/Unit9-Inheritance/topic-9-1-inheritance-day1.rst @@ -25,7 +25,7 @@ :align: right Inheritance (Day 1) -------------------- +=================== One of the really useful features of Object-Oriented programming is **inheritance**. You may have heard of someone coming into an inheritance, which often means they were left something from a relative who died. Or, you might hear someone say that they have inherited musical ability from a parent. In Java all classes can **inherit** attributes (instance variables) and behaviors (methods) from another class. The class being inherited from is called the **parent class** or **superclass**. The class that is inheriting is called the **child class** or **subclass**. @@ -181,4 +181,4 @@ The Student class can also inherit from the class Person just like Employee and boolean passed = checkCodeContains("Student extends Person"); assertTrue(passed); } - } \ No newline at end of file + } diff --git a/_sources/Unit9-Inheritance/topic-9-1-inheritance-day2.rst b/_sources/Unit9-Inheritance/topic-9-1-inheritance-day2.rst index b211bea8..8e3e344f 100644 --- a/_sources/Unit9-Inheritance/topic-9-1-inheritance-day2.rst +++ b/_sources/Unit9-Inheritance/topic-9-1-inheritance-day2.rst @@ -25,7 +25,7 @@ :align: right is-a vs. has-a (Day 2) ---------------------------------------- +====================== .. index:: single: has-a From 254df08381a4c9457c5bf8077b21a89656d918bb Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 10:15:20 -0700 Subject: [PATCH 10/31] Get rid of some inline style that is messing up XML --- .../Unit1-Getting-Started/topic-1-5-shortcutoperators.rst | 5 ----- _sources/Unit3-If-Statements/topic-3-5-compound-ifs.rst | 4 ---- _sources/Unit3-If-Statements/topic-3-6-DeMorgan.rst | 6 +----- _sources/Unit7-ArrayList/topic-7-2-arraylist-methods.rst | 4 ---- _sources/Unit7-ArrayList/topic-7-5-searching.rst | 4 ---- 5 files changed, 1 insertion(+), 22 deletions(-) diff --git a/_sources/Unit1-Getting-Started/topic-1-5-shortcutoperators.rst b/_sources/Unit1-Getting-Started/topic-1-5-shortcutoperators.rst index 4f3c57aa..4ad2cd1f 100644 --- a/_sources/Unit1-Getting-Started/topic-1-5-shortcutoperators.rst +++ b/_sources/Unit1-Getting-Started/topic-1-5-shortcutoperators.rst @@ -19,11 +19,6 @@ :align: middle :alt: groupwork -.. raw:: html - - - - .. index:: single: operators pair: math; operators diff --git a/_sources/Unit3-If-Statements/topic-3-5-compound-ifs.rst b/_sources/Unit3-If-Statements/topic-3-5-compound-ifs.rst index da913876..cb0709b1 100644 --- a/_sources/Unit3-If-Statements/topic-3-5-compound-ifs.rst +++ b/_sources/Unit3-If-Statements/topic-3-5-compound-ifs.rst @@ -23,10 +23,6 @@ :align: middle :alt: groupwork -.. raw:: html - - - .. image:: ../../_static/time90.png :width: 225 :align: right diff --git a/_sources/Unit3-If-Statements/topic-3-6-DeMorgan.rst b/_sources/Unit3-If-Statements/topic-3-6-DeMorgan.rst index be506e1a..3bcca8a5 100644 --- a/_sources/Unit3-If-Statements/topic-3-6-DeMorgan.rst +++ b/_sources/Unit3-If-Statements/topic-3-6-DeMorgan.rst @@ -19,10 +19,6 @@ :align: middle :alt: groupwork -.. raw:: html - - - .. image:: ../../_static/time90.png :width: 225 :align: right @@ -393,4 +389,4 @@ Summary - Truth tables can be used to prove that 2 Boolean expressions are identical. -- Equivalent Boolean expressions will evaluate to the same value in all cases. \ No newline at end of file +- Equivalent Boolean expressions will evaluate to the same value in all cases. diff --git a/_sources/Unit7-ArrayList/topic-7-2-arraylist-methods.rst b/_sources/Unit7-ArrayList/topic-7-2-arraylist-methods.rst index 32d11daa..be6a4ef1 100644 --- a/_sources/Unit7-ArrayList/topic-7-2-arraylist-methods.rst +++ b/_sources/Unit7-ArrayList/topic-7-2-arraylist-methods.rst @@ -23,10 +23,6 @@ :width: 250 :align: right -.. raw:: html - - - ArrayList Methods ========================= diff --git a/_sources/Unit7-ArrayList/topic-7-5-searching.rst b/_sources/Unit7-ArrayList/topic-7-5-searching.rst index c0e13b4d..6b998a1b 100644 --- a/_sources/Unit7-ArrayList/topic-7-5-searching.rst +++ b/_sources/Unit7-ArrayList/topic-7-5-searching.rst @@ -19,10 +19,6 @@ :align: middle :alt: groupwork -.. raw:: html - - - .. image:: ../../_static/time90.png :width: 225 :align: right From 6b64717920937674e54f659bf63ce651beec7e3d Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 10:43:47 -0700 Subject: [PATCH 11/31] Some more sections/subsection fixes. --- .../Unit10-Recursion/topic-10-1-recursion-challenge.rst | 2 +- _sources/Unit10-Recursion/topic-10-1-recursion-day1.rst | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/_sources/Unit10-Recursion/topic-10-1-recursion-challenge.rst b/_sources/Unit10-Recursion/topic-10-1-recursion-challenge.rst index 75d71c7b..e567b355 100644 --- a/_sources/Unit10-Recursion/topic-10-1-recursion-challenge.rst +++ b/_sources/Unit10-Recursion/topic-10-1-recursion-challenge.rst @@ -134,7 +134,7 @@ Once strMethod("y") returns, the value from each recursive call on the stack can Summary -============ +------- - A recursive method is a method that calls itself. diff --git a/_sources/Unit10-Recursion/topic-10-1-recursion-day1.rst b/_sources/Unit10-Recursion/topic-10-1-recursion-day1.rst index e6b7e403..4dbb0bf2 100644 --- a/_sources/Unit10-Recursion/topic-10-1-recursion-day1.rst +++ b/_sources/Unit10-Recursion/topic-10-1-recursion-day1.rst @@ -106,7 +106,7 @@ This method will print out "This is the method that never ends!" and then call i Why use Recursion? -================== +------------------ .. index:: single: fractal @@ -126,7 +126,7 @@ Recursion can also be used to create fractals. A simple example is Sierpinski's Recursion can also be used to traverse String, array, and ArrayList objects, much like a loop. In fact, any recursive solution could be written with iteration (loops) instead. Factorial Method -================= +---------------- The following video is also on YouTube at https://youtu.be/V2S_8E_ubBY. It introduces the concept of recursion and tracing recursion with the factorial method. @@ -209,7 +209,7 @@ See the method `factorial` below that calculates the **factorial** of a number. Base Case -========== +--------- .. index:: single: base case @@ -307,4 +307,4 @@ Every recursive method must have at least one **base case** which halts the recu } -Continue to the next page for Day 2 of the Recursion lesson. \ No newline at end of file +Continue to the next page for Day 2 of the Recursion lesson. From 2bd539c11512c7824400a22910674f0b5be2d463 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 10:55:04 -0700 Subject: [PATCH 12/31] Move xmlificitaion of br's into fix-xml.pl --- fix-xml.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/fix-xml.pl b/fix-xml.pl index ddc1cb7e..b366fa6a 100755 --- a/fix-xml.pl +++ b/fix-xml.pl @@ -24,6 +24,7 @@ s{\[, , \]}{[<q>, </q>, </q>]}g; s/i <"/i <"/g; s/"//g; print; } From 0e641ae518d2fefcccd383cdbaebeb9b7db68a1e Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 10:55:54 -0700 Subject: [PATCH 13/31] Kludge to deal with top-level images breaking XML --- fix.pl | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/fix.pl b/fix.pl index 459f2fea..1c2bce81 100755 --- a/fix.pl +++ b/fix.pl @@ -3,21 +3,21 @@ use warnings; use strict; -my $OPEN_LT = "TAG_PLACEHOLDER_SHOULD_NOT_EXIST_IN_FEEDBACK"; +my $OPEN_LT = "LESS_THAN_PLACEHOLDER_SHOULD_NOT_EXIST_IN_ACTUAL_TEXT"; $^I = ''; while (<>) { - # Some blocks start with .. .. which seems to get translated to a comment - # but if the block then contains --- that's not something that can appear in - # an XML comment. - s/^\.\. \.\./../; - - #if (/<\w+\s+.*?[-a-z]+=(?!['"])/) { - # die "$_"; - #} + # These are images put at the top of some pages. When converting to XML that + # causes the XML document to not have a single root element. So we make them + # into image references for now. Later on we'll have to figure out how to put + # the images back into the rendered HTML. + s{.. (image:: (\.\./)+_static/time)}{.. |ClockImageToBeFixed| $1}g; + s{.. (image:: (\.\./)+_static/CSAwesomeLogo.png)}{.. |LogoImageToBeFixed| $1}g; + # Specific fixes for some items that in the .rst contain some HTML which is + # occasionally broken and often contains unescaped & and <. if (/^\s+:(feedback|answer)/) { if (/$OPEN_LT/) { @@ -41,9 +41,6 @@ # Put back the tag <'s. s/$OPEN_LT/ tags to be XMLish. - s/
//g; - } print; } From 86769882db32d0cc7df034742508e230cc86d3e3 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 10:56:05 -0700 Subject: [PATCH 14/31] Tidy Makefile a bit. --- Makefile | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 96412528..5f93e22e 100644 --- a/Makefile +++ b/Makefile @@ -15,18 +15,31 @@ fix: xml: $(rs2ptx) -fix_xml: +fixed_xml: xml find build/xml -name '*.xml' -exec ./fix-xml.pl {} \; +# This works better pretext/%.ptx: build/xml/%.xml | pretext mkdir -p $(dir $@) xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@ +# This works but produces .ptx files that don't get through post cleanly. +all_ptx: | pretext + python $(R2P)/xml2ptx.py . + ptx: $(ptx) +post: + python $(R2P)/fixIds.py + python $(R2P)/fix_xrefs.py + python $(R2P)/reformatPtx.py + pretext: mkdir $@ clean: rm -rf pretext rm -rf build/xml + +pristine: clean + git restore _sources From 5f84951cd8cb9ae0af24e33664d9409203859e7e Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 11:45:14 -0700 Subject: [PATCH 15/31] Tidying Makefile --- Makefile | 8 ++++---- fix.pl => fix-source.pl | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename fix.pl => fix-source.pl (100%) diff --git a/Makefile b/Makefile index 5f93e22e..e4ebdb40 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,11 @@ ptx := $(patsubst build/xml/%.xml,pretext/%.ptx,$(xml)) # This will run from a virtual env. rs2ptx := python -m runestone rs2ptx -all: - @echo $(ptx) +all: fixed_source fixed_xml + $(MAKE) ptx post -fix: - find _sources/ -name '*.rst' -exec ./fix.pl {} \; +fixed_source: + find _sources/ -name '*.rst' -exec ./fix-source.pl {} \; xml: $(rs2ptx) diff --git a/fix.pl b/fix-source.pl similarity index 100% rename from fix.pl rename to fix-source.pl From 269b03fc710c82c79746a8f0420c739b8b2e5484 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 11:46:40 -0700 Subject: [PATCH 16/31] Tidying fix-xml --- fix-xml.pl | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/fix-xml.pl b/fix-xml.pl index b366fa6a..c7e1b098 100755 --- a/fix-xml.pl +++ b/fix-xml.pl @@ -1,5 +1,10 @@ #!/usr/bin/env perl +# +# A bunch of ad-hoc fixes to the generated XML, mostly dealing with places where +# the content contains characters that need to be escaped in XML. +# + use warnings; use strict; @@ -7,24 +12,29 @@ while (<>) { - s/ArrayList<([A-Z])/ArrayList<$1/g; + # More or less ad-hoc escaping of special XML characters. + s/\b([A-Z]\w+)<([A-Z]\w+)>/$1<$2>/g; s/ArrayList<(int)>/ArrayList<$1>/g; s/ArrayList<>/ArrayList<>/g; - s/ <( |=)/ <$1/g; s/len<=/len<=/g; s/ &&( |$)/ &&$1/g; s/ & / & /g; s/"&&"/"&&"/g; - s/\b([A-Z]\w+)<([A-Z]\w+)>/$1<$2>/g; - s/data-optional=true/data-optional="true"/g; - s/'data-optional="true"'/'data-optional=true'/g; s/&&<\/cline>/&&<\/cline>/g; s/"<(\/?(sup|q))>"/"<$1>"/g; s{\[, , \]}{[<q>, </q>, </q>]}g; s/i <"/i <"/g; - s/"//g; + s/"//g; + print; } From 551358eec274167bf46e0fe8e412c8c6b9e38408 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 12:41:10 -0700 Subject: [PATCH 17/31] Get rid of Old TOC section --- _sources/Unit2-Using-Objects/toctree.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/_sources/Unit2-Using-Objects/toctree.rst b/_sources/Unit2-Using-Objects/toctree.rst index 71f5c4c6..23b9a490 100644 --- a/_sources/Unit2-Using-Objects/toctree.rst +++ b/_sources/Unit2-Using-Objects/toctree.rst @@ -33,12 +33,3 @@ AP CS A Exam Weighting: 5-7.5% Exercises.rst JavaSwingGUIs.rst -.. Old TOC - whatIsJava.rst - introClassObject.rst - firstClass.rst - compileTimeErrors.rst - firstOOClass.rst - runClass.rst - partsOfAClass.rst - JavaBasicsSummary.rst \ No newline at end of file From 9d132a778fa1f9036f5ed971869b84b741fcded1 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sat, 10 Jun 2023 13:31:39 -0700 Subject: [PATCH 18/31] Add build_web to Makefile --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index e4ebdb40..f02279ca 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: all fixed_source xml fixed_xml ptx post fix_ids post2 post3 build_web clean pristine + R2P := ~/3rdparty/Runestone2PreTeXt xml := $(shell find build/xml -type f) @@ -33,6 +35,16 @@ post: python $(R2P)/fixIds.py python $(R2P)/fix_xrefs.py python $(R2P)/reformatPtx.py + cp main.ptx pretext + cp publication-rs-for-all.xml pretext + python $(R2P)/toctree2xml.py . + python $(R2P)/copy_figs.py ./_source ./pretext/Figures + +fix_ids: + python $(R2P)/fixIds.py + +build_web: + pretext build web pretext: mkdir $@ From 675b76726499826a01444197d5fe725e5bd2490a Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 09:50:30 -0700 Subject: [PATCH 19/31] Fixup PreTeXt to include when needed. --- Makefile | 3 ++- post.xsl | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 post.xsl diff --git a/Makefile b/Makefile index f02279ca..2a6a5863 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,8 @@ fixed_xml: xml # This works better pretext/%.ptx: build/xml/%.xml | pretext mkdir -p $(dir $@) - xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@ + xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@.pass1 + xsltproc --novalid post.xsl $@.pass1 > $@ # This works but produces .ptx files that don't get through post cleanly. all_ptx: | pretext diff --git a/post.xsl b/post.xsl new file mode 100644 index 00000000..75b88270 --- /dev/null +++ b/post.xsl @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + From d23c0bffe508de4163d55f722dfa1f96004ca356 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 09:55:28 -0700 Subject: [PATCH 20/31] Fix width attributes --- fix-source.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fix-source.pl b/fix-source.pl index 1c2bce81..19d15613 100755 --- a/fix-source.pl +++ b/fix-source.pl @@ -5,6 +5,8 @@ my $OPEN_LT = "LESS_THAN_PLACEHOLDER_SHOULD_NOT_EXIST_IN_ACTUAL_TEXT"; +my $max_width = 850; + $^I = ''; while (<>) { @@ -16,6 +18,14 @@ s{.. (image:: (\.\./)+_static/time)}{.. |ClockImageToBeFixed| $1}g; s{.. (image:: (\.\./)+_static/CSAwesomeLogo.png)}{.. |LogoImageToBeFixed| $1}g; + + # PreTeXt wants all widths in percents. This is a dumb kludge to get them + # somewhere in the right ballpark. + if (/^(\s+:width:\s+)(\d+)(?:px)?(.*)/) { + my $p = 100 * ($2 / $max_width); + $_ = sprintf "%s%.0f%%%s\n", $1, $p, $3; + } + # Specific fixes for some items that in the .rst contain some HTML which is # occasionally broken and often contains unescaped & and <. if (/^\s+:(feedback|answer)/) { From 7c686d15e2601e2893f84f9fc6fd9ed89b6f1b23 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 09:55:46 -0700 Subject: [PATCH 21/31] Strip height attributes that PreTeXt doesn't like. --- post.xsl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/post.xsl b/post.xsl index 75b88270..3c71631a 100644 --- a/post.xsl +++ b/post.xsl @@ -15,4 +15,8 @@ + + + + From 8ec41bcd64194850d6b8745a13e47ff9c945c390 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 10:18:01 -0700 Subject: [PATCH 22/31] Some more XML post processing. --- post.xsl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/post.xsl b/post.xsl index 3c71631a..45cec0c3 100644 --- a/post.xsl +++ b/post.xsl @@ -6,7 +6,8 @@ - + + @@ -16,7 +17,28 @@ - + + + + + + + + + + + + + + + + + + + + + + From fd0fc60968f3a361d75216a48070aa8e1e4263f2 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 11:32:24 -0700 Subject: [PATCH 23/31] Adding another stage to XML fixups. --- Makefile | 3 ++- fix-source.pl | 8 -------- post-1.xsl | 19 +++++++++++++++++++ post.xsl => post-2.xsl | 12 ++++++++++-- 4 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 post-1.xsl rename post.xsl => post-2.xsl (75%) diff --git a/Makefile b/Makefile index 2a6a5863..44c54140 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ fixed_xml: xml pretext/%.ptx: build/xml/%.xml | pretext mkdir -p $(dir $@) xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@.pass1 - xsltproc --novalid post.xsl $@.pass1 > $@ + xsltproc --novalid post-1.xsl $@.pass1 > $@.pass2 + xsltproc --novalid post-2.xsl $@.pass2 > $@ # This works but produces .ptx files that don't get through post cleanly. all_ptx: | pretext diff --git a/fix-source.pl b/fix-source.pl index 19d15613..dd7a8c4a 100755 --- a/fix-source.pl +++ b/fix-source.pl @@ -18,14 +18,6 @@ s{.. (image:: (\.\./)+_static/time)}{.. |ClockImageToBeFixed| $1}g; s{.. (image:: (\.\./)+_static/CSAwesomeLogo.png)}{.. |LogoImageToBeFixed| $1}g; - - # PreTeXt wants all widths in percents. This is a dumb kludge to get them - # somewhere in the right ballpark. - if (/^(\s+:width:\s+)(\d+)(?:px)?(.*)/) { - my $p = 100 * ($2 / $max_width); - $_ = sprintf "%s%.0f%%%s\n", $1, $p, $3; - } - # Specific fixes for some items that in the .rst contain some HTML which is # occasionally broken and often contains unescaped & and <. if (/^\s+:(feedback|answer)/) { diff --git a/post-1.xsl b/post-1.xsl new file mode 100644 index 00000000..7d42d46d --- /dev/null +++ b/post-1.xsl @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/post.xsl b/post-2.xsl similarity index 75% rename from post.xsl rename to post-2.xsl index 45cec0c3..d93cee03 100644 --- a/post.xsl +++ b/post-2.xsl @@ -11,9 +11,9 @@ - + - + @@ -40,5 +40,13 @@ + + + + + % + + + From 61b0f0fb3d71270ac2e758eab61ea263ed9e80cc Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 13:56:03 -0700 Subject: [PATCH 24/31] Only put lines in when there are br's. --- post-2.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-2.xsl b/post-2.xsl index d93cee03..72ab7bdc 100644 --- a/post-2.xsl +++ b/post-2.xsl @@ -32,7 +32,7 @@ - + From 1c9bd62f7011ecd7a3ff615e0de4ad8bd1c4295a Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 16:22:40 -0700 Subject: [PATCH 25/31] Remove interviewees we don't have files for. --- _sources/Stories/intervieweeIndex.rst | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/_sources/Stories/intervieweeIndex.rst b/_sources/Stories/intervieweeIndex.rst index cc75512d..860e25b0 100644 --- a/_sources/Stories/intervieweeIndex.rst +++ b/_sources/Stories/intervieweeIndex.rst @@ -1,4 +1,4 @@ -.. image:: ../../_static/CSAwesomeLogo.png +.. |LogoImageToBeFixed| image:: ../../_static/CSAwesomeLogo.png :width: 350 :align: center @@ -18,16 +18,8 @@ Meet The Interviewees Interviewees/E_Espinoza.rst Interviewees/G_Opoku-Boateng.rst Interviewees/J_Gilbert.rst + Interviewees/L_Diaz.rst Interviewees/L_Morales.rst Interviewees/L_Vocos.rst - Interviewees/L_Diaz.rst Interviewees/M_Rodriguez.rst Interviewees/N_Gaskins.rst - Interviewees/O_Romero.rst - Interviewees/R_Garcia.rst - Interviewees/R_Tillman-French.rst - Interviewees/S_Seibel.rst - Interviewees/S_Vivas.rst - Interviewees/T_Pope.rst - Interviewees/W_Sheppard.rst - Interviewees/Y_Salazar.rst \ No newline at end of file From 1c5b22aa396561a90965174e5b316113048e2173 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 17:56:45 -0700 Subject: [PATCH 26/31] Copy attributes. --- post-2.xsl | 1 + 1 file changed, 1 insertion(+) diff --git a/post-2.xsl b/post-2.xsl index 72ab7bdc..59932948 100644 --- a/post-2.xsl +++ b/post-2.xsl @@ -10,6 +10,7 @@ + From e66e5c6dc5efb823a5c905f70bf1f8707c82dd71 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Sun, 11 Jun 2023 20:05:16 -0700 Subject: [PATCH 27/31] Add fix-ptx script for a few xrefs. --- Makefile | 26 ++++++++++++++------------ fix-ptx.pl | 21 +++++++++++++++++++++ fix-xml.pl | 4 +++- 3 files changed, 38 insertions(+), 13 deletions(-) create mode 100755 fix-ptx.pl diff --git a/Makefile b/Makefile index 44c54140..3acac5ea 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ .PHONY: all fixed_source xml fixed_xml ptx post fix_ids post2 post3 build_web clean pristine +DEBUG_PRETEXT := # -v DEBUG R2P := ~/3rdparty/Runestone2PreTeXt xml := $(shell find build/xml -type f) @@ -9,7 +10,7 @@ ptx := $(patsubst build/xml/%.xml,pretext/%.ptx,$(xml)) rs2ptx := python -m runestone rs2ptx all: fixed_source fixed_xml - $(MAKE) ptx post + $(MAKE) ptx post fixed_ptx build_web fixed_source: find _sources/ -name '*.rst' -exec ./fix-source.pl {} \; @@ -20,18 +21,18 @@ xml: fixed_xml: xml find build/xml -name '*.xml' -exec ./fix-xml.pl {} \; -# This works better +fixed_ptx: + find pretext -name '*.ptx' -exec ./fix-ptx.pl {} \; + +# This works better than the script that does them all pretext/%.ptx: build/xml/%.xml | pretext mkdir -p $(dir $@) xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@.pass1 xsltproc --novalid post-1.xsl $@.pass1 > $@.pass2 xsltproc --novalid post-2.xsl $@.pass2 > $@ + cp $@ $@.pass3 -# This works but produces .ptx files that don't get through post cleanly. -all_ptx: | pretext - python $(R2P)/xml2ptx.py . - -ptx: $(ptx) +ptx: $(ptx) pretext/rs-substitutes.xml post: python $(R2P)/fixIds.py @@ -40,17 +41,18 @@ post: cp main.ptx pretext cp publication-rs-for-all.xml pretext python $(R2P)/toctree2xml.py . - python $(R2P)/copy_figs.py ./_source ./pretext/Figures - -fix_ids: - python $(R2P)/fixIds.py + python $(R2P)/filltoc.py pretext _sources + python $(R2P)/copy_figs.py ./_sources ./pretext/Figures build_web: - pretext build web + pretext $(DEBUG_PRETEXT) build web pretext: mkdir $@ +pretext/rs-substitutes.xml: rs-substitutes.xml | pretext + cp $< $@ + clean: rm -rf pretext rm -rf build/xml diff --git a/fix-ptx.pl b/fix-ptx.pl new file mode 100755 index 00000000..83f670a4 --- /dev/null +++ b/fix-ptx.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl + +# +# Ad-hoc fixes to the generated ptx that aren't worth trying to handle properly +# in the conversion and XML rewriting. +# + +use warnings; +use strict; + +$^I = ''; + +while (<>) { + + # Translate xml:ids that were generated in the docs to the ones used in the xrefs. + s/xml:id="_briceida-mariscal-id1-\d+"/xml:id="interviewees_b_-mariscal"/g; + s/xml:id="_carla-de-lira-id1-\d+"/xml:id="interviewees_c_-de_-lira"/g; + s/xml:id="_camille-mbayo-id1-\d+"/xml:id="interviewees_c_-mbayo"/g; + + print; +} diff --git a/fix-xml.pl b/fix-xml.pl index c7e1b098..1a14ae06 100755 --- a/fix-xml.pl +++ b/fix-xml.pl @@ -12,7 +12,8 @@ while (<>) { - # More or less ad-hoc escaping of special XML characters. + # More or less ad-hoc escaping of special XML characters. Some of these may no + # longer be needed as I fixed at least part of the escaping of activecode nodes. s/\b([A-Z]\w+)<([A-Z]\w+)>/$1<$2>/g; s/ArrayList<(int)>/ArrayList<$1>/g; s/ArrayList<>/ArrayList<>/g; @@ -21,6 +22,7 @@ s/ &&( |$)/ &&$1/g; s/ & / & /g; s/"&&"/"&&"/g; + s/&&<\/cline>/&&<\/cline>/g; s/"<(\/?(sup|q))>"/"<$1>"/g; s{\[, , \]}{[<q>, </q>, </q>]}g; From ff4d6b266f4448e15128547fe8112f87f933424c Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Mon, 12 Jun 2023 15:13:43 -0700 Subject: [PATCH 28/31] One more try to get this regex right. --- fix-ptx.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fix-ptx.pl b/fix-ptx.pl index 83f670a4..0c22fe93 100755 --- a/fix-ptx.pl +++ b/fix-ptx.pl @@ -13,9 +13,9 @@ while (<>) { # Translate xml:ids that were generated in the docs to the ones used in the xrefs. - s/xml:id="_briceida-mariscal-id1-\d+"/xml:id="interviewees_b_-mariscal"/g; - s/xml:id="_carla-de-lira-id1-\d+"/xml:id="interviewees_c_-de_-lira"/g; - s/xml:id="_camille-mbayo-id1-\d+"/xml:id="interviewees_c_-mbayo"/g; + s/xml:id="_briceida-mariscal-id1(-\d+)?"/xml:id="interviewees_b_-mariscal"/g; + s/xml:id="_carla-de-lira-id1(-\d+)?"/xml:id="interviewees_c_-de_-lira"/g; + s/xml:id="_camille-mbayo-id1(-\d+)?"/xml:id="interviewees_c_-mbayo"/g; print; } From 4a3b92e18eebf5f4d9a74eb2fb3bec27d2594711 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Tue, 13 Jun 2023 15:40:54 -0700 Subject: [PATCH 29/31] Generalized structure for hand fixed files. --- Makefile | 5 +- hand-fixes/Unit8-2DArray/routeCipherA.ptx | 581 ++++++++++++++++++++++ 2 files changed, 584 insertions(+), 2 deletions(-) create mode 100644 hand-fixes/Unit8-2DArray/routeCipherA.ptx diff --git a/Makefile b/Makefile index 3acac5ea..76d5a6af 100644 --- a/Makefile +++ b/Makefile @@ -23,14 +23,15 @@ fixed_xml: xml fixed_ptx: find pretext -name '*.ptx' -exec ./fix-ptx.pl {} \; + rsync -r hand-fixes/ pretext/ # This works better than the script that does them all pretext/%.ptx: build/xml/%.xml | pretext mkdir -p $(dir $@) xsltproc --novalid $(R2P)/docutils2ptx.xsl $< > $@.pass1 xsltproc --novalid post-1.xsl $@.pass1 > $@.pass2 - xsltproc --novalid post-2.xsl $@.pass2 > $@ - cp $@ $@.pass3 + xsltproc --novalid post-2.xsl $@.pass2 > $@.pass3 + cp $@.pass3 $@ ptx: $(ptx) pretext/rs-substitutes.xml diff --git a/hand-fixes/Unit8-2DArray/routeCipherA.ptx b/hand-fixes/Unit8-2DArray/routeCipherA.ptx new file mode 100644 index 00000000..6b465bd8 --- /dev/null +++ b/hand-fixes/Unit8-2DArray/routeCipherA.ptx @@ -0,0 +1,581 @@ + + +
+ + Free Response - Route Cipher A +

The following is a free response question from 2011. It was question 4 on the exam. You can see all the free response questions from past exams at https://apstudents.collegeboard.org/courses/ap-computer-science-a/free-response-questions-by-year.

+

Question 4. In this question you will write two methods for a class RouteCipher that encrypts (puts into a coded form) a message by changing the order of the characters in the message. The route cipher fills a two-dimensional array with single-character substrings of the original message in row-major order, encrypting the message by retrieving the single-character substrings in column-major order.

+

For example, the word “Surprise” can be encrypted using a 2-row, 4-column array as follows.

+
+ +
+

An incomplete implementation of the RouteCipher class is shown below.

+ + +public class RouteCipher +{ + /** A two-dimensional array of single-character strings, + instantiated in the constructor */ + private String[][] letterBlock; + + /** The number of rows of letterBlock, set by the constructor */ + private int numRows; + + /** The number of columns of letterBlock, set by the constructor */ + private int numCols; + + /** Places a string into letterBlock in row-major order. + * @param str the string to be processed + * Postcondition: + * if str.length() < numRows * numCols, "A" in each unfilled cell + * if str.length() > numRows * numCols, trailing characters are ignored + */ + public void fillBlock(String str) + { /* to be implemented in part (a) */ } + + /** Extracts encrypted string from letterBlock in column-major order. + * Precondition: letterBlock has been filled + * @return the encrypted string from letterBlock + */ + private String encryptBlock() + { /* implementation not shown */ } + + /** Encrypts a message. + * @param message the string to be encrypted + * @return the encrypted message; + * if message is the empty string, returns the empty string + */ + public String encryptMessage(String message) + { /* to be implemented in part (b) */ } + + // There may be instance variables, constructors, and methods that are not shown +} + + +

Part a. + Write the method fillBlock that fills the two-dimensional array letterBlock with one-character strings from the string passed as parameter str.

+

The array must be filled in row-major order—the first row is filled from left to right, then the second row is filled from left to right, and so on, until all rows are filled.

+

If the length of the parameter str is smaller than the number of elements of the array, the string “A” is placed in each of the unfilled cells. If the length of str is larger than the number of elements in the array, the trailing characters are ignored.

+

For example, if letterBlock has 3 rows and 5 columns and str is the string “Meet at noon”, the resulting contents of letterBlock would be as shown in the following table.

+
+ +
+

If letterBlock has 3 rows and 5 columns and str is the string “Meet at midnight”, the resulting contents of letterBlock would be as shown in the following table.

+
+ +
+

The following expression may be used to obtain a single-character string at position k of the string str.

+ + +str.substring(k, k + 1) + + +
+ + How to Solve This + + +

9-12-1: Explain in plain English what your code will have to do to answer this question. Use the variable names given above.

+
+
+

This section contains a plain English explanation of one way to solve this problem as well as problems that test your understanding of how to write the code to do those things. + Click on the buttons to reveal the questions.

+ +

You will need to access each element in the letterBlock array. What type of loop will you use?

+ + + +

9-12-2: What type of loop should you use?

+
+ + + +

for each

+
+ +

We need to utilize elements by indexing them so a for each loop will not work

+
+
+ + +

if

+
+ +

This is not a type of loop

+
+
+ + +

for

+
+ +

Correct!

+
+
+ + +

while

+
+ +

Although this could would, we would need some kind of tracker variable to allow use to count indexes which would be more easily accomplished by a different loop.

+
+
+ + +

switch statement

+
+ +

This would not work in this situation.

+
+
+
+
+
+

The letterBlock array has two dimensions. How many loops will you use?

+ + + +

9-12-3: How many Loops should you use?

+
+ + + +

1

+
+ +

This would not correctly iterate through the 2D array

+
+
+ + +

2, nested

+
+ +

Correct!

+
+
+ + +

2, un-nested

+
+ +

This would not correctly iterate through the 2D array

+
+
+ + +

3, un-nested

+
+ +

This would not correctly iterate through the 2D array

+
+
+
+
+
+
+ + + +

9-12-4: What can you use to set the outer bound while you iterate through your 2D array?

+
+ + + +

numRows

+
+ +

Correct!

+
+
+ + +

numCols

+
+ +

No, numCols finds the width and we are iterating through this in row-major order.

+
+
+ + +

str.length()

+
+ +

This finds us the length of the string but the array is not based on the string length.

+
+
+ + +

str[0].length()

+
+ +

Strings aren't defined under the '[]' operator and str is not a 2D array so this would return an error.

+
+
+
+
+
+ + + +

9-12-5: What can you use to set the inner bound while you iterate through your 2D array?

+
+ + + +

numRows

+
+ +

No, numRows finds the width and should not be used as the inner bound because we are iterating through the array in row-major order.

+
+
+ + +

numCols

+
+ +

Correct!

+
+
+ + +

str.length()

+
+ +

This finds us the length of the string but the array is not based on the string length.

+
+
+ + +

str[0].length()

+
+ +

Strings aren't defined under the '[]' operator and str is not a 2D array so this would return an error.

+
+
+
+
+
+ + + +

9-12-6: Which String method can you use to access partial or full strings within another string?

+
+ + + +

str.length()

+
+ +

This does not return a string

+
+
+ + +

str(lowerbound, upperbound)

+
+ +

This is not a valid string method

+
+
+ + +

str.subsection(lowerbound, upperbound)

+
+ +

This is not a valid string method

+
+
+ + +

str.substring(lowerbound, upperbound)

+
+ +

Correct!

+
+
+
+
+
+
+ + The Algorithm + + + +

9-12-7: What is the formula for obtaining a single-character string at position k of the string str?

+
+ + + +

str.substring(k, k)

+
+ +

This will not return the correct char correctly

+
+
+ + +

str.substring(k + 1, k + 1)

+
+ +

This will not return the correct char correctly

+
+
+ + +

str.substring(k, k + 1)

+
+ +

Correct!

+
+
+ + +

str.substring(k + 1, k)

+
+ +

This will not return the correct char correctly

+
+
+
+
+
+ + + +

9-12-8: How can one find the aforementioned k? (this is hard to visualize, try drawing out some examples)

+
+ + + +

str.substring(c + r * this.numCols, 1 + c + r * this.numCols)

+
+ +

Correct!

+
+
+ + +

str.substring(c - r * this.numCols, 1 + c - r * this.numCols)

+
+ +

Try using this formula to find a given character of one of the example strings. Does it work? Try coming up with some of your own examples to figure out the forumla for k.

+
+
+ + +

str.substring(c + r, 1 + c + r)

+
+ +

Try using this formula to find a given character of one of the example strings. Does it work? Try coming up with some of your own examples to figure out the forumla for k.

+
+
+ + +

str.substring(c - r, 1 + c - r)

+
+ +

Try using this formula to find a given character of one of the example strings. Does it work? Try coming up with some of your own examples to figure out the forumla for k.

+
+
+
+
+
+ + + +

9-12-9: What conditional can you write to make sure trailing characters are ignored?

+
+ + + +

if (str.length() < (c + (r * this.numCols)))

+
+ +

This will not return the correct boolean

+
+
+ + +

if (str.length() > (c + (r * this.numCols)))

+
+ +

Correct!

+
+
+ + +

if (str.length() > numRows * numCols)

+
+ +

We need to determine whether or not to ignore trialing character at each step, not just check for it once at the beginning.

+
+
+ + +

if (str.length() < numRows * numCols)

+
+ +

We need to determine whether or not to ignore trialing character at each step, not just check for it once at the beginning.

+
+
+
+
+
+

The exercises above have been guiding you towards just one of many possible solutions. To read through a different solution, click on the Reveal + button below and complete the problem.

+ + + +

The method fillBlock below contains the correct code for one solution to this problem, but it is mixed up and contains extra blocks that are not needed. Drag the needed code from the left to the right and put them in order with the correct indention so that the code would work correctly.

+
+ + + public void fillBlock(String str) { + int pos = 0; + + + for (int r = 0; r < this.numRows; r++ ) { + + + for (int c = 0; c < this.numCols; c++ ) { + + + if (pos < str.length()) { + + + String subStr = str.substring(pos, pos+1); + this.letterBlock[r][c] = subStr; + pos++; + + + } else { + this.letterBlock[r][c] = "A"; + } // end else block + + + } // end inner for + + + } // end outer for + + + } // end method + + +
+
+
+ + Try And Solve It + + +

Complete the method fillBlock below.

+
+ + +public class RouteCipher +{ + /** A two-dimensional array of single-character strings, instantiated in the constructor */ + public String[][] letterBlock; + + /** The number of rows of letterBlock, set by the constructor */ + private int numRows; + + /** The number of columns of letterBlock, set by the constructor */ + private int numCols; + + public RouteCipher(int r, int c){ + this.letterBlock = new String[r][c]; + this.numRows = r; + this.numCols = c; + } + + /** Places a string into letterBlock in row-major order. + * @param str the string to be processed + * Postcondition: + * if str.length() < numRows * numCols, "A" in each unfilled cell + * if str.length() > numRows * numCols, trailing characters are ignored + */ + public void fillBlock(String str) + { + // Complete this method + + + + } + + /** Extracts encrypted string from letterBlock in column-major order. + * Precondition: letterBlock has been filled + * @return the encrypted string from letterBlock + */ + private String encryptBlock() + { return ""; } + + /** Encrypts a message. + * @param message the string to be encrypted + * @return the encrypted message; + * if message is the empty string, returns the empty string + */ + public String encryptMessage(String message) + { return ""; } + + public static void main(String[] args) + { + + boolean test1 = false; + RouteCipher ciph = new RouteCipher(3, 3); + + ciph.fillBlock("There's 1"); + + if((ciph.letterBlock[0][2]).equals("e") && (ciph.letterBlock[2][1]).equals(" ")) + test1 = true; + else + System.out.println("Oops! Looks like your code doesn't properly insert the given String.\n"); + + if(test1) + System.out.println("Looks like your code works well!"); + else + System.out.println("Make a few changes, please."); + + } +} +==== +import static org.junit.Assert.*; + import org.junit.*; + import java.io.*; + import java.util.List; + import java.util.ArrayList; + import java.util.Arrays; + + public class RunestoneTests extends CodeTestHelper + { + + @Test + public void testMain() throws IOException + { + String output = getMethodOutput("main"); + String expect = "Looks like your code works well!\n" ; + + boolean passed = getResults(expect, output, "Expected output from main"); + assertTrue(passed); + } + + + @Test + public void test1() + { + RouteCipher ciph = new RouteCipher(3, 4); + + ciph.fillBlock("Lady Bugs"); + + String result = String.valueOf((ciph.letterBlock[0][2]).equals("d") && (ciph.letterBlock[2][2]).equals("A"));boolean passed = getResults("true", result, "method fillBlock works"); + assertTrue(passed); + } + } + + +
+
+
From 4bf06f3867aa14c134c6ead5c0a4220734ee6150 Mon Sep 17 00:00:00 2001 From: Peter Seibel Date: Thu, 15 Jun 2023 19:51:15 -0700 Subject: [PATCH 30/31] README about the conversion. --- README_PRETEXT.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 README_PRETEXT.md diff --git a/README_PRETEXT.md b/README_PRETEXT.md new file mode 100644 index 00000000..f2a5b3a3 --- /dev/null +++ b/README_PRETEXT.md @@ -0,0 +1,47 @@ +This branch was created mostly as an experiment to see how far I could get with +converting to PreTeXt. The basic idea was to try and automate as much as +possible so I'd be able to rerun the conversion from the latest rst source +whenever. However I didn't totally stick to that plan and made a few changes to +the .rst files. Some of them may be fixes that should be made for their own sake +but a bunch of them were just hacks to get the rst into a format where it would +convert cleanly; in particular I had to rip out several `.. raw:: html` sections +that added `