Skip to content

Exercises - Protein Translation - Patch 1 (to clarify biological terminology) #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions exercises/practice/protein-translation/.meta/example.c
Original file line number Diff line number Diff line change
@@ -5,11 +5,11 @@ enum { codon_length = 3 };

typedef struct {
const char *const codon;
protein_t protein;
amino_acid_t amino_acid;
bool stop;
} protein_translation_t;
} amino_acid_translation_t;

static const protein_translation_t translations[] = {
static const amino_acid_translation_t translations[] = {
{ "AUG", Methionine, false },
{ "UUU", Phenylalanine, false },
{ "UUC", Phenylalanine, false },
@@ -31,9 +31,9 @@ static const protein_translation_t translations[] = {
static const size_t translation_count =
sizeof(translations) / sizeof(translations[0]);

proteins_t proteins(const char *const rna)
protein_t protein(const char *const rna)
{
proteins_t proteins = { .valid = true, .count = 0 };
protein_t protein = { .valid = true, .count = 0 };

size_t rna_length = strlen(rna);

@@ -43,20 +43,21 @@ proteins_t proteins(const char *const rna)
for (size_t j = 0; j < translation_count; j++) {
if (strncmp(rna + i, translations[j].codon, codon_length) == 0) {
if (translations[j].stop) {
return proteins;
return protein;
} else {
proteins.proteins[proteins.count++] = translations[j].protein;
protein.amino_acids[protein.count++] =
translations[j].amino_acid;
found_codon = true;
break;
}
}
}

if (!found_codon) {
proteins.valid = false;
return proteins;
protein.valid = false;
return protein;
}
}

return proteins;
return protein;
}
10 changes: 5 additions & 5 deletions exercises/practice/protein-translation/.meta/example.h
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
#include <stdbool.h>
#include <stddef.h>

#define MAX_PROTEINS 10
#define MAX_AMINO_ACIDS 10

typedef enum {
Methionine,
@@ -14,14 +14,14 @@ typedef enum {
Tyrosine,
Cysteine,
Tryptophan,
} protein_t;
} amino_acid_t;

typedef struct {
bool valid;
size_t count;
protein_t proteins[MAX_PROTEINS];
} proteins_t;
amino_acid_t amino_acids[MAX_AMINO_ACIDS];
} protein_t;

proteins_t proteins(const char *const rna);
protein_t protein(const char *const rna);

#endif
10 changes: 5 additions & 5 deletions exercises/practice/protein-translation/protein_translation.h
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
#include <stdbool.h>
#include <stddef.h>

#define MAX_PROTEINS 10
#define MAX_AMINO_ACIDS 10

typedef enum {
Methionine,
@@ -14,14 +14,14 @@ typedef enum {
Tyrosine,
Cysteine,
Tryptophan,
} protein_t;
} amino_acid_t;

typedef struct {
bool valid;
size_t count;
protein_t proteins[MAX_PROTEINS];
} proteins_t;
amino_acid_t amino_acids[MAX_AMINO_ACIDS];
} protein_t;

proteins_t proteins(const char *const rna);
protein_t protein(const char *const rna);

#endif
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.