Skip to content
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

run-length-encoding-exercise: added new exercise. #115

Merged

Conversation

SimaDovakin
Copy link
Contributor

Added new exercise for #48in24.

Copy link

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

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


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@github-actions github-actions bot closed this Jun 29, 2024
@keiravillekode
Copy link
Contributor

It would be excellent if we had a instructions.append.md that explains the memory addresses the student's solution is expected to use.

If I understand correctly, your example solution uses some memory near address 0 and some memory near address 320, in addition to the memory for the input string.

Should we perhaps be passing in a destination address?

@SimaDovakin
Copy link
Contributor Author

In instructions.append.md, I mentioned that the buffer for the input string uses bytes 64-319 of linear memory. I use the memory from 0 as the main input memory and the memory from 320 for storing the digits of a number to convert them to a number. But, maybe, there are other solutions that don't require the memory from 320. I think, it is enough to specify the input memory range. Am I right? Maybe I missed something.

@keiravillekode
Copy link
Contributor

My solutions on other low-level tracks would write the digits to the output in reverse order, and then reverse in place.

@SimaDovakin
Copy link
Contributor Author

I also do it in encode function (actually in $numberToString). But for decode function I store digits in the memory from 320th byte and then consume them to get a single number. I did it because I need to know the number of digits to determine the power of ten for the last digits (123 = 1 * 10^2 + 2 * 10^1 + 3 * 10^0). I have no idea is there a way to do this conversion without storing digits.

@keiravillekode
Copy link
Contributor

(123 = 1 * 10^2 + 2 * 10^1 + 3 * 10^0).

number = 0
for digit in digits:
  number = number * 10 + (digit - '0')

0 * 10 + 1 gives 1
1 * 10 + 2 gives 12
12 * 10 + 3 gives 123

@SimaDovakin
Copy link
Contributor Author

Cool! Thank you. I'll try to reimplement this part of my solution.

@SimaDovakin
Copy link
Contributor Author

@keiravillekode Done. I changed the number consuming in decode function. Anything else?

@keiravillekode
Copy link
Contributor

keiravillekode commented Jul 1, 2024

@ErikSchierboom - we can't see the updates until the PR is reopened.

I think we can merge this and we might want to refine or expand instructions.append.md afterwards. A flood of people will attempt this exercise for #48in24 and we want them to have an excellent experience.

In a month or two, we can decide on sample solutions for Dig Deeper.

Here are my two suggestions:

One solution for this exercise would overwrite the input with the output. For the decode case, I would compute the output length and work backwards from the end to the start, returning early as soon as there are no more digits - so decode "abc10d2e" would write 2 'e' characters, then the 10 'd' characters and then return.

Another solution would write the output immediately after the input in memory - assuming instructions.append.md can be phrased such that this is a permissible solution. Perhaps with wording like "There is also sufficient space for the output string, both before and after the input string." This example solution would generate the encode output initially reversed, and reverse in place at the very end. So encode 'abbbbbbbbbbbbc' would write 'cb21a' and then reverse that.

@ErikSchierboom ErikSchierboom reopened this Jul 2, 2024
@ErikSchierboom
Copy link
Member

This Now has a merge conflict

@SimaDovakin
Copy link
Contributor Author

I'll resolve it.

@SimaDovakin
Copy link
Contributor Author

@ErikSchierboom Done

@ErikSchierboom ErikSchierboom merged commit cc2bfe7 into exercism:main Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants