exercism / j

Exercism exercises in J.
https://exercism.org/tracks/j
MIT License
8 stars 9 forks source link

Test shape of output from to_rna #116

Closed wilhelm-now closed 4 months ago

wilhelm-now commented 5 months ago

Hi, I'm a beginner to J and tried the rna-transcription exercise. My first imperative attempt started with an empty string and did a while loop appending individual transcribed characters to the output.

transcribe =: monad : 0
out =. ''
select. y
case. 'G' do. out =. 'C'
case. 'C' do. out =. 'G'
case. 'T' do. out =. 'A'
case. 'A' do. out =. 'U'
end.
out
)

to_rna=: monad : 0
out =. ''
count =. # y
i =. 0
while. i < count do.
 out =. out , transcribe i { y
 i =. i + 1
end.
out
)

Visually this prints expected results but the shape is not preserved when the input is only one character.

   $ 'C'           NB. empty print is expected https://www.jsoftware.com/help/primer/shape.htm

   $ to_rna 'G'
1

It took me a while to understand that this is the reason tests 2, 3, 4, and 5 failed. Would it help if there was a test for preserving shape of input?

github-actions[bot] commented 5 months ago

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use this link%0D%0A%0D%0Ato_rna=:%20monad%20:%200%0D%0Aout%20=.%20''%0D%0Acount%20=.%20#%20y%0D%0Ai%20=.%200%0D%0Awhile.%20i%20%3C%20count%20do.%0D%0A%20out%20=.%20out%20,%20transcribe%20i%20%7B%20y%0D%0A%20i%20=.%20i%20+%201%0D%0Aend.%0D%0Aout%0D%0A)%0D%0A%60%60%60%0D%0A%0D%0AVisually%20this%20prints%20expected%20results%20but%20the%20shape%20is%20not%20preserved%20when%20the%20input%20is%20only%20one%20character.%0D%0A%0D%0A%60%60%60%0D%0A%20%20%20$%20'C'%20%20%20%20%20%20%20%20%20%20%20NB.%20empty%20print%20is%20expected%20https://www.jsoftware.com/help/primer/shape.htm%0D%0A%0D%0A%20%20%20$%20to_rna%20'G'%0D%0A1%0D%0A%60%60%60%0D%0A%0D%0AIt%20took%20me%20a%20while%20to%20understand%20that%20this%20is%20the%20reason%20tests%202,%203,%204,%20and%205%20failed.%20Would%20it%20help%20if%20there%20was%20a%20test%20for%20preserving%20shape%20of%20input?&category=j ) to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.

ErikSchierboom commented 5 months ago

@eNascimento178 Something for you to consider.

eNascimento178 commented 4 months ago

I will choose the -:&, option for this case and, at a later moment, include a message in the analyser highlighting the issue with the shapes after the student creates the solution plus some hints If stuck.