Computer Science Principles
Course Progress
0/0
Objectives in LxD
3.4 Strings
3.4 Strings
Crowdsourcing Lesson
3.3 Mathematical Expressions
3.3 Math Expressions
3.2 Data Abstractions
3.2 Data Abstractions
3.2 Data Abstractions
3.1 Variables & Assignments
3.1 Variables and Assignments
3.1 Variables and Assignments (Sample)
Intro to Python
Intro to Javascript
3.5 Boolean Expressions (PY)
3.5 Boolean Expressions (JS)
3.8 Iterations
3.7 Nested Conditionals
3.6 Conditionals
3.8 Iterations
3.7 Nested Conditionals
3.6 Conditionals
3.13 Developing Procedures
3.12 Calling Procedures
3.10 Lists
3.13 Developing Procedures
3.10 Lists
3.9 Developing Algorithms
3.17 Algorithmic Efficiency
3.9 Algorithms
3.17 Algorithmic Efficiency
3.15 Random Numbers (pseudocode)
3.15 Random Numbers (js)
3.15 Random Numbers (py)
BI 3 Review
Data Frames | Pandas | Intro 1
ML | Titanic Data
ML | Fitness
ML | Neural Network | Handwritting Detection
Data Frames | Pandas | Intro 2
Network Stack | HTTP and TCP/IP
API | Request | Response | Database
Data | SQL Connect
Data | SQLAlchemy
Data | Binary Logic
Computer System | Web Server | Flask
Topic 1.4 - Identifying and Correcting Errors
Single Responsibility & API Chaining
Computing Systems | AWS Deployment | Setup Applicationa
Computing Systems | AWS Deployment | Launch EC2
Computing System | AWS Deployment| Step-by-Step Guide
AP CSP Pseudocode Runner
6 min read
Pseudocode Runner
This notebook allows you to run AP CSP pseudocode directly in JavaScript. You can write your pseudocode in the cells below, and it will be executed as JavaScript code. This is a great way to test your understanding of pseudocode and see how it translates to actual code.
Pseudocode Keyword Reference (click to expand)
All keywords are **case-sensitive and must be written in ALL CAPS**. Type `<--` for `←`, `!=` for `≠`, `>=` for `≥`, `<=` for `≤`.Variables & Assignment
Use `←` to assign a value. Variables are created on first assignment. Variable names are case-sensitive. ``` x ← 5 name ← "Alice" flag ← TRUE ``` > Types: numbers, strings (`"double quotes"`), `TRUE` / `FALSE`DISPLAY & INPUT
| Command | What it does | |---|---| | `DISPLAY(value)` | Prints a value to the output box | | `INPUT("prompt")` | Prompts the user; auto-converts to number/boolean if possible | ``` DISPLAY("Hello!") age ← INPUT("Enter your age: ") DISPLAY(age) ```Operators
**Arithmetic:** `+` `-` `*` `/` `MOD` > `+` also concatenates strings **Comparison:** `=` `≠` `<` `>` `≤` `≥` **Logical:** `AND` `OR` `NOT` ``` DISPLAY(10 MOD 3) // 1 DISPLAY(5 = 5) // TRUE DISPLAY(TRUE AND FALSE) // FALSE DISPLAY(NOT FALSE) // TRUE ```IF / ELSE
``` IF (condition) { // runs if TRUE } ELSE { // runs if FALSE (ELSE block is optional) } ``` ``` x ← 7 IF (x > 5) { DISPLAY("big") } ELSE { DISPLAY("small") } ```Loops
**REPEAT n TIMES** ``` REPEAT 5 TIMES { DISPLAY("hello") } ``` **REPEAT UNTIL** — loops until condition is `TRUE` ``` x ← 0 REPEAT UNTIL (x = 5) { x ← x + 1 } ``` **FOR EACH IN** — iterates over a list ``` FOR EACH n IN [1, 2, 3] { DISPLAY(n * 2) } ```Lists
**1-based indexing** — first element is at index `1`. | Command | What it does | |---|---| | `list[i]` | Get element at index `i` | | `list[i] ← value` | Set element at index `i` | | `APPEND(list, value)` | Add to end | | `INSERT(list, i, value)` | Insert at index `i` | | `REMOVE(list, i)` | Remove at index `i` | | `LENGTH(list)` | Number of elements | ``` nums ← [10, 20, 30] APPEND(nums, 40) DISPLAY(LENGTH(nums)) // 4 DISPLAY(nums[1]) // 10 ```PROCEDURE & RETURN
``` PROCEDURE add(a, b) { RETURN a + b } DISPLAY(add(3, 4)) // 7 ``` Procedures without `RETURN` can still be called for side effects: ``` PROCEDURE greet(name) { DISPLAY("Hello, " + name) } greet("Alice") ```Robot / Grid Commands
These activate the visual 7x7 grid. Write setup lines first, then movement logic below. **Setup** (stripped before execution) | Command | What it does | |---|---| | `FROM TILEMAPS IMPORT N` | Load preset map N (1-25) | | `SPAWN CHARACTER AT (col, row)` | Place robot at col, row (1-based), facing up | | `SPAWN GOAL AT (col, row)` | Place a goal star | **Movement** (called at runtime) | Command | What it does | |---|---| | `MOVE_FORWARD()` | Move one cell forward | | `ROTATE_LEFT()` | Turn 90 degrees counter-clockwise | | `ROTATE_RIGHT()` | Turn 90 degrees clockwise | | `CAN_MOVE("direction")` | TRUE if passable - "forward" "backward" "left" "right" | ``` FROM TILEMAPS IMPORT 12 SPAWN CHARACTER AT (1,1) SPAWN GOAL AT (7,7) REPEAT UNTIL (CAN_MOVE("forward") = FALSE) { MOVE_FORWARD() } ROTATE_RIGHT() MOVE_FORWARD() ```Custom Tilemaps (RENDER)
Instead of loading a preset with `FROM TILEMAPS IMPORT`, define your own 7x7 grid as a variable and pass it to `RENDER()`. **Rules:** - The matrix must be a **list of 7 lists**, each with exactly **7 values** - `0` = open cell, `1` = wall - The entire assignment must be on **one line** - Call `RENDER(variable)` before any movement commands ``` myMap ← [[0,0,0,0,0,0,0],[0,1,1,0,0,1,0],[0,0,1,0,0,0,0],[0,0,0,0,1,0,0],[0,1,0,0,1,0,0],[0,1,0,0,0,0,0],[0,0,0,0,0,0,0]] SPAWN CHARACTER AT (1,1) SPAWN GOAL AT (7,7) RENDER(myMap) MOVE_FORWARD() ROTATE_RIGHT() MOVE_FORWARD() ``` > You can combine both: use `FROM TILEMAPS IMPORT N` to load a preset, then call `RENDER(newMap)` later to swap the grid mid-execution.Tilemap Directory — IDs 1–25 (click to expand)
Use these IDs with `from tilemaps import N`. All maps are 7×7, 0 = open, 1 = wall. | ID | Name | Description | |---|---|---| | 1 | Scattered walls | Open grid with a few wall clusters — good starter map | | 2 | Column gaps | Vertical wall pairs with clear corridors between them | | 3 | Double gate | Two horizontal barriers each with a single opening in the centre | | 4 | Staggered columns | Alternating column walls; open row in the middle connects them | | 5 | Ring | Solid 5×5 wall ring with an open interior and outer path | | 6 | Diamond obstacles | Symmetric diagonal obstacles around a centre wall | | 7 | Cross barrier | Plus-sign wall with a single gap on each axis | | 8 | Dot grid | Regular 2×2 wall dots across the grid — many equal paths | | 9 | S-curve | Single-width path: left → down → right → down | | 10 | T-junction | Open top row splits into two shafts that merge to a single exit | | 11 | Two rooms | Wall divides the grid; one corridor connects the rooms at row 4 | | 12 | Zigzag slalom | Barriers alternate sides — forces full end-to-end traversal | | 13 | Diagonal obstacles | Diagonal line of single-cell walls; open space on both sides | | 14 | Slalom barriers | Two staggered barriers each with one opening — weave through | | 15 | Winding river | Narrow single-width path snaking from top-left to bottom-right | | 16 | Cross open | Plus-sign open area in the centre; corners are walled off | | 17 | Perimeter loop | Outer ring is fully open; solid 5×5 block in the interior | | 18 | Grid maze | Open intersections with wall segments — multiple valid routes | | 19 | Columns | Tall wall columns with one open row in the middle | | 20 | Honeycomb | Staggered single-cell obstacles; lots of routing options | | 21 | Staircase | 2-wide diagonal path from top-left to bottom-right | | 22 | Scattered obstacles | Mostly open with light random single-cell walls | | 23 | L-corridor | Left column + bottom row form an L-shaped path | | 24 | Double loop | Four 2×2 wall blocks leave open rings and a centre cross | | 25 | Funnel | Wide open top narrows to a single-column corridor at the bottom |Code Runner Challenge
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...