-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
240b298
commit b0cb909
Showing
14 changed files
with
3,810 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
exercises/practice/kindergarten-garden/.docs/instructions.append.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Output format | ||
|
||
Output the student's plants as a null-terminated string, using a comma and a space as separators. |
56 changes: 56 additions & 0 deletions
56
exercises/practice/kindergarten-garden/.docs/instructions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Instructions | ||
|
||
Your task is to, given a diagram, determine which plants each child in the kindergarten class is responsible for. | ||
|
||
There are 12 children in the class: | ||
|
||
- Alice, Bob, Charlie, David, Eve, Fred, Ginny, Harriet, Ileana, Joseph, Kincaid, and Larry. | ||
|
||
Four different types of seeds are planted: | ||
|
||
| Plant | Diagram encoding | | ||
| ------ | ---------------- | | ||
| Grass | G | | ||
| Clover | C | | ||
| Radish | R | | ||
| Violet | V | | ||
|
||
Each child gets four cups, two on each row: | ||
|
||
```text | ||
[window][window][window] | ||
........................ # each dot represents a cup | ||
........................ | ||
``` | ||
|
||
Their teacher assigns cups to the children alphabetically by their names, which means that Alice comes first and Larry comes last. | ||
|
||
Here is an example diagram representing Alice's plants: | ||
|
||
```text | ||
[window][window][window] | ||
VR...................... | ||
RG...................... | ||
``` | ||
|
||
In the first row, nearest the windows, she has a violet and a radish. | ||
In the second row she has a radish and some grass. | ||
|
||
Your program will be given the plants from left-to-right starting with the row nearest the windows. | ||
From this, it should be able to determine which plants belong to each student. | ||
|
||
For example, if it's told that the garden looks like so: | ||
|
||
```text | ||
[window][window][window] | ||
VRCGVVRVCGGCCGVRGCVCGCGV | ||
VRCCCGCRRGVCGCRVVCVGCGCV | ||
``` | ||
|
||
Then if asked for Alice's plants, it should provide: | ||
|
||
- Violets, radishes, violets, radishes | ||
|
||
While asking for Bob's plants would yield: | ||
|
||
- Clover, grass, clover, clover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Introduction | ||
|
||
The kindergarten class is learning about growing plants. | ||
The teacher thought it would be a good idea to give the class seeds to plant and grow in the dirt. | ||
To this end, the children have put little cups along the window sills and planted one type of plant in each cup. | ||
The children got to pick their favorites from four available types of seeds: grass, clover, radishes, and violets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"keiravillekode" | ||
], | ||
"files": { | ||
"solution": [ | ||
"kindergarten_garden.asm" | ||
], | ||
"test": [ | ||
"kindergarten_garden_test.c" | ||
], | ||
"example": [ | ||
".meta/example.asm" | ||
] | ||
}, | ||
"blurb": "Given a diagram, determine which plants each child in the kindergarten class is responsible for.", | ||
"source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.", | ||
"source_url": "https://turing.edu" | ||
} |
109 changes: 109 additions & 0 deletions
109
exercises/practice/kindergarten-garden/.meta/example.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
default rel | ||
|
||
section .rodata | ||
clover: db "clover", 0 | ||
grass: db "grass", 0 | ||
radishes: db "radishes", 0 | ||
violets: db "violets", 0 | ||
comma: db ", ", 0 | ||
|
||
section .data | ||
plant_array: | ||
dq 0 | ||
dq 0 | ||
dq clover | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq grass | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq radishes | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq violets | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
dq 0 | ||
|
||
section .text | ||
global plants | ||
|
||
; Outputs the student's plants as a null-terminated string, using a comma and a space as separators. | ||
; rdi - output buffer | ||
; rsi - garden diagram | ||
; rdx - student's name | ||
; r8 - start of garden diagram | ||
; r9 - length of garden diagram, halved | ||
; r10 - plant array | ||
; rbx - offset into garden diagram | ||
; rcx - current plant | ||
plants: | ||
cld ; each lodsb will increase rsi | ||
push rbx | ||
xor rcx, rcx | ||
mov r8, rsi | ||
lea r10, [plant_array] | ||
|
||
.scan: | ||
lodsb | ||
test al, al | ||
jnz .scan | ||
|
||
mov r9, rsi | ||
sub r9, r8 | ||
inc r9 | ||
shr r9, 1 | ||
|
||
xor rbx, rbx | ||
mov bl, byte [rdx] | ||
sub bl, 'A' | ||
shl bl, 1 ; index into diagram for first plant: 2 * (student[0] - `A`) | ||
call .output_plant | ||
call .output_comma | ||
|
||
inc bl ; index into diagram for second plant | ||
call .output_plant | ||
call .output_comma | ||
|
||
dec bl | ||
add rbx, r9 ; index into diagram for third plant | ||
call .output_plant | ||
call .output_comma | ||
|
||
inc bl ; index into diagram for fourth plant | ||
call .output_plant | ||
pop rbx | ||
ret | ||
|
||
.output_plant: | ||
mov cl, byte [r8 + rbx] | ||
sub cl, 'A' | ||
mov rsi, qword [r10 + 8 * rcx] | ||
|
||
.copy_string: | ||
lodsb | ||
stosb | ||
test al, al | ||
jnz .copy_string | ||
|
||
dec rdi | ||
ret | ||
|
||
.output_comma: | ||
lea rsi, [comma] | ||
jmp .copy_string | ||
|
||
%ifidn __OUTPUT_FORMAT__,elf64 | ||
section .note.GNU-stack noalloc noexec nowrite progbits | ||
%endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[1fc316ed-17ab-4fba-88ef-3ae78296b692] | ||
description = "partial garden -> garden with single student" | ||
|
||
[acd19dc1-2200-4317-bc2a-08f021276b40] | ||
description = "partial garden -> different garden with single student" | ||
|
||
[c376fcc8-349c-446c-94b0-903947315757] | ||
description = "partial garden -> garden with two students" | ||
|
||
[2d620f45-9617-4924-9d27-751c80d17db9] | ||
description = "partial garden -> multiple students for the same garden with three students -> second student's garden" | ||
|
||
[57712331-4896-4364-89f8-576421d69c44] | ||
description = "partial garden -> multiple students for the same garden with three students -> third student's garden" | ||
|
||
[149b4290-58e1-40f2-8ae4-8b87c46e765b] | ||
description = "full garden -> for Alice, first student's garden" | ||
|
||
[ba25dbbc-10bd-4a37-b18e-f89ecd098a5e] | ||
description = "full garden -> for Bob, second student's garden" | ||
|
||
[566b621b-f18e-4c5f-873e-be30544b838c] | ||
description = "full garden -> for Charlie" | ||
|
||
[3ad3df57-dd98-46fc-9269-1877abf612aa] | ||
description = "full garden -> for David" | ||
|
||
[0f0a55d1-9710-46ed-a0eb-399ba8c72db2] | ||
description = "full garden -> for Eve" | ||
|
||
[a7e80c90-b140-4ea1-aee3-f4625365c9a4] | ||
description = "full garden -> for Fred" | ||
|
||
[9d94b273-2933-471b-86e8-dba68694c615] | ||
description = "full garden -> for Ginny" | ||
|
||
[f55bc6c2-ade8-4844-87c4-87196f1b7258] | ||
description = "full garden -> for Harriet" | ||
|
||
[759070a3-1bb1-4dd4-be2c-7cce1d7679ae] | ||
description = "full garden -> for Ileana" | ||
|
||
[78578123-2755-4d4a-9c7d-e985b8dda1c6] | ||
description = "full garden -> for Joseph" | ||
|
||
[6bb66df7-f433-41ab-aec2-3ead6e99f65b] | ||
description = "full garden -> for Kincaid, second to last student's garden" | ||
|
||
[d7edec11-6488-418a-94e6-ed509e0fa7eb] | ||
description = "full garden -> for Larry, last student's garden" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
AS = nasm | ||
|
||
CFLAGS = -g -Wall -Wextra -pedantic -Werror | ||
LDFLAGS = | ||
ASFLAGS = -g -F dwarf -Werror | ||
|
||
ifeq ($(shell uname -s),Darwin) | ||
ifeq ($(shell sysctl -n hw.optional.arm64 2>/dev/null),1) | ||
ALL_CFLAGS = -target x86_64-apple-darwin | ||
endif | ||
ALL_LDFLAGS = -Wl,-pie | ||
ALL_ASFLAGS = -f macho64 --prefix _ | ||
else | ||
ALL_LDFLAGS = -pie -Wl,--fatal-warnings | ||
ALL_ASFLAGS = -f elf64 | ||
endif | ||
|
||
ALL_CFLAGS += -std=c99 -fPIE -m64 $(CFLAGS) | ||
ALL_LDFLAGS += $(LDFLAGS) | ||
ALL_ASFLAGS += $(ASFLAGS) | ||
|
||
C_OBJS = $(patsubst %.c,%.o,$(wildcard *.c)) | ||
AS_OBJS = $(patsubst %.asm,%.o,$(wildcard *.asm)) | ||
ALL_OBJS = $(filter-out example.o,$(C_OBJS) $(AS_OBJS) vendor/unity.o) | ||
|
||
CC_CMD = $(CC) $(ALL_CFLAGS) -c -o $@ $< | ||
|
||
all: tests | ||
@./$< | ||
|
||
tests: $(ALL_OBJS) | ||
@$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $(ALL_OBJS) | ||
|
||
%.o: %.asm | ||
@$(AS) $(ALL_ASFLAGS) -o $@ $< | ||
|
||
%.o: %.c | ||
@$(CC_CMD) | ||
|
||
vendor/unity.o: vendor/unity.c vendor/unity.h vendor/unity_internals.h | ||
@$(CC_CMD) | ||
|
||
clean: | ||
@rm -f *.o vendor/*.o tests | ||
|
||
.PHONY: all clean |
12 changes: 12 additions & 0 deletions
12
exercises/practice/kindergarten-garden/kindergarten_garden.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
default rel | ||
|
||
section .text | ||
global plants | ||
|
||
plants: | ||
; Provide your implementation here | ||
ret | ||
|
||
%ifidn __OUTPUT_FORMAT__,elf64 | ||
section .note.GNU-stack noalloc noexec nowrite progbits | ||
%endif |
Oops, something went wrong.