File tree Expand file tree Collapse file tree 1 file changed +4
-9
lines changed
Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change @@ -51,15 +51,15 @@ func encodeTernaryToDNA(ternaryStr string) string {
5151
5252// Decodes a DNA sequence (nucleotides) back to a ternary string (sequence of trits)
5353func decodeDNAToTernary (dnaSeq string ) (string , error ) {
54- var ternaryStr strings.Builder
5554 if len (dnaSeq ) == 0 {
5655 return "" , fmt .Errorf ("empty DNA sequence" )
5756 }
5857
58+ var ternaryStr strings.Builder
5959 previousNucleotide := byte ('A' )
60+
6061 for i := 0 ; i < len (dnaSeq ); i ++ {
6162 nextNucleotide := dnaSeq [i ]
62-
6363 trit := reverseLookupTable [previousNucleotide ][nextNucleotide ]
6464 ternaryStr .WriteByte (byte (trit ) + '0' ) // Convert to ASCII character
6565 previousNucleotide = nextNucleotide
@@ -70,18 +70,13 @@ func decodeDNAToTernary(dnaSeq string) (string, error) {
7070
7171func encode (data []byte ) string {
7272 ternaryStr := byteArrayToTernary ([]byte (data ))
73- dnaSequence := encodeTernaryToDNA (ternaryStr )
74-
75- return dnaSequence
73+ return encodeTernaryToDNA (ternaryStr )
7674}
7775
7876func decode (dnaSeq string ) ([]byte , error ) {
7977 ternaryStr , err := decodeDNAToTernary (dnaSeq )
8078 if err != nil {
8179 return nil , err
8280 }
83-
84- byteArray := ternaryToByteArray (ternaryStr )
85-
86- return byteArray , nil
81+ return ternaryToByteArray (ternaryStr ), nil
8782}
You can’t perform that action at this time.
0 commit comments