-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
e6d1842
commit 6a88603
Showing
13 changed files
with
3,530 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
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,9 @@ | ||
# Instructions | ||
|
||
Your task is to reverse a given string. | ||
|
||
Some examples: | ||
|
||
- Turn `"stressed"` into `"desserts"`. | ||
- Turn `"strops"` into `"sports"`. | ||
- Turn `"racecar"` into `"racecar"`. |
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,5 @@ | ||
# Introduction | ||
|
||
Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming. | ||
|
||
For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance. |
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": [ | ||
"reverse_string.s" | ||
], | ||
"test": [ | ||
"reverse_string_test.c" | ||
], | ||
"example": [ | ||
".meta/example.s" | ||
] | ||
}, | ||
"blurb": "Reverse a given string.", | ||
"source": "Introductory challenge to reverse an input string", | ||
"source_url": "https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb" | ||
} |
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,30 @@ | ||
.text | ||
.globl reverse | ||
|
||
/* extern void reverse(char *str); */ | ||
reverse: | ||
mov x1, x0 | ||
|
||
.scan: | ||
ldrb w2, [x1], #1 /* load byte, post-increment */ | ||
cbnz w2, .scan | ||
|
||
sub x1, x1, #1 | ||
cmp x1, x0 | ||
beq .done /* zero length string */ | ||
|
||
.reverse: | ||
sub x1, x1, #1 | ||
cmp x1, x0 | ||
beq .done /* middle byte of odd length string */ | ||
|
||
ldrb w2, [x1] | ||
ldrb w3, [x0] | ||
strb w3, [x1] | ||
strb w2, [x0], #1 /* store byte, post-increment */ | ||
cmp x1, x0 | ||
bne .reverse | ||
/* middle bytes of even length string */ | ||
|
||
.done: | ||
ret |
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,40 @@ | ||
# 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. | ||
|
||
[c3b7d806-dced-49ee-8543-933fd1719b1c] | ||
description = "an empty string" | ||
|
||
[01ebf55b-bebb-414e-9dec-06f7bb0bee3c] | ||
description = "a word" | ||
|
||
[0f7c07e4-efd1-4aaa-a07a-90b49ce0b746] | ||
description = "a capitalized word" | ||
|
||
[71854b9c-f200-4469-9f5c-1e8e5eff5614] | ||
description = "a sentence with punctuation" | ||
|
||
[1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c] | ||
description = "a palindrome" | ||
|
||
[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c] | ||
description = "an even-sized word" | ||
|
||
[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2] | ||
description = "wide characters" | ||
include = false | ||
|
||
[93d7e1b8-f60f-4f3c-9559-4056e10d2ead] | ||
description = "grapheme cluster with pre-combined form" | ||
include = false | ||
|
||
[1028b2c1-6763-4459-8540-2da47ca512d9] | ||
description = "grapheme clusters" | ||
include = false |
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,36 @@ | ||
AS = aarch64-linux-gnu-as | ||
CC = aarch64-linux-gnu-gcc | ||
|
||
CFLAGS = -g -Wall -Wextra -pedantic -Werror | ||
LDFLAGS = | ||
|
||
ALL_LDFLAGS = -pie -Wl,--fatal-warnings | ||
|
||
ALL_CFLAGS = -std=c99 -fPIE $(CFLAGS) | ||
ALL_LDFLAGS += $(LDFLAGS) | ||
|
||
C_OBJS = $(patsubst %.c,%.o,$(wildcard *.c)) | ||
AS_OBJS = $(patsubst %.s,%.o,$(wildcard *.s)) | ||
ALL_OBJS = $(filter-out example.o,$(C_OBJS) $(AS_OBJS) vendor/unity.o) | ||
|
||
CC_CMD = $(CC) $(ALL_CFLAGS) -c -o $@ $< | ||
|
||
all: tests | ||
qemu-aarch64 -L /usr/aarch64-linux-gnu ./$< | ||
|
||
tests: $(ALL_OBJS) | ||
@$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $(ALL_OBJS) | ||
|
||
%.o: %.s | ||
@$(AS) -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 |
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,5 @@ | ||
.text | ||
.globl reverse | ||
|
||
reverse: | ||
ret |
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 @@ | ||
#include "vendor/unity.h" | ||
|
||
extern void reverse(char *str); | ||
|
||
void setUp(void) { | ||
} | ||
|
||
void tearDown(void) { | ||
} | ||
|
||
void test_an_empty_string(void) { | ||
char str[] = ""; | ||
reverse(str); | ||
TEST_ASSERT_EQUAL_STRING("", str); | ||
} | ||
|
||
void test_a_word(void) { | ||
TEST_IGNORE(); | ||
char str[] = "robot"; | ||
reverse(str); | ||
TEST_ASSERT_EQUAL_STRING("tobor", str); | ||
} | ||
|
||
void test_a_capitalized_word(void) { | ||
TEST_IGNORE(); | ||
char str[] = "Ramen"; | ||
reverse(str); | ||
TEST_ASSERT_EQUAL_STRING("nemaR", str); | ||
} | ||
|
||
void test_a_sentence_with_punctuation(void) { | ||
TEST_IGNORE(); | ||
char str[] = "I'm hungry!"; | ||
reverse(str); | ||
TEST_ASSERT_EQUAL_STRING("!yrgnuh m'I", str); | ||
} | ||
|
||
void test_a_palindrome(void) { | ||
TEST_IGNORE(); | ||
char str[] = "racecar"; | ||
reverse(str); | ||
TEST_ASSERT_EQUAL_STRING("racecar", str); | ||
} | ||
|
||
void test_an_evensized_word(void) { | ||
TEST_IGNORE(); | ||
char str[] = "drawer"; | ||
reverse(str); | ||
TEST_ASSERT_EQUAL_STRING("reward", str); | ||
} | ||
|
||
int main(void) { | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_an_empty_string); | ||
RUN_TEST(test_a_word); | ||
RUN_TEST(test_a_capitalized_word); | ||
RUN_TEST(test_a_sentence_with_punctuation); | ||
RUN_TEST(test_a_palindrome); | ||
RUN_TEST(test_an_evensized_word); | ||
return UNITY_END(); | ||
} |
Oops, something went wrong.