exercism / c

Exercism exercises in C.
https://exercism.org/tracks/c
MIT License
294 stars 182 forks source link

Exercises for #48in24 #940

Open siebenschlaefer opened 9 months ago

siebenschlaefer commented 9 months ago

Dear maintainers,

Jeremy posted an overview of the exercises that will be featured in #48in24: http://forum.exercism.org/t/which-exercises-for-48in24/8970/19

The following featured exercises have not been translated to C yet:

I'm posting them here as a reminder. I hope I will find the time to translate a few of them, and perhaps others will help, too. Feel free to close or remove this issue if you do not find it helpful.

Edit:
There is now a dedicated matrix with the status of all exercises in #48in24, which tracks have implemented them, and which exercises are featured on a specific track: https://exercism.org/challenges/48in24/implementation_status

ryanplusplus commented 9 months ago

Thanks for the heads up. I'll pick up some as I get time. If anyone would like to grab one, please leave a note here first so that no one else starts work on the same exercise.

ahans commented 9 months ago

I will try to contribute kindergarten-garden.

ryanplusplus commented 9 months ago

I'm going to grab spiral-matrix

ryanplusplus commented 9 months ago

I'm also going to grab protein-translation

siebenschlaefer commented 9 months ago

I'm also going to grab protein-translation

Somebody on the forum wanted to help with that. Although they didn't reply in the last two days.

ryanplusplus commented 9 months ago

I'm also going to grab protein-translation

Somebodyon the forum wanted to help with that. Although they didn't reply in the last two days.

Thanks for the heads up. I'll give them another few days to respond.

ahans commented 9 months ago

Opened a PR for pop-count as well since it was so trivial.

ryanplusplus commented 9 months ago

I'm going to grab knapsack

siebenschlaefer commented 8 months ago

I've given the zebra-puzzle a shot (#959)

ahans commented 7 months ago

Put me down for yacht. I will probably get around to implement something next week.

ahans commented 7 months ago

This was quicker than expected: https://github.com/exercism/c/pull/972

ahans commented 7 months ago

I also gave rotational-cipher a shot: https://github.com/exercism/c/pull/975

ahans commented 7 months ago

Feel free to also put me down for dnd-character and food-chain.

ahans commented 7 months ago

About parallel-letter-frequency and bank-account, I wonder what approaches we want to support there, since both are about some form of parallelism and there's nothing in the C standard (library) to support this. pthreads would probably be the most natural, but OpenMP could also be an option? The latter would also work natively on Windows with MSVC, although the instructions about working locally sound like we don't want to support this anyways. What do you think?

wolf99 commented 7 months ago

About parallel-letter-frequency and bank-account, I wonder what approaches we want to support there, since both are about some form of parallelism and there's nothing in the C standard (library) to support this. pthreads would probably be the most natural, but OpenMP could also be an option? The latter would also work natively on Windows with MSVC, although the instructions about working locally sound like we don't want to support this anyways. What do you think?

Threading is not really in my wheelhouse so I have more questions than answers 😄 I will point out first that the paralllel aspect of the exercises is not mandatory (the spec for bank-account talks about this specifically), so one option is to implement them without the parallelism. If we do add parallelism...

ahans commented 7 months ago

Alright, implementing bank-account without the parallel aspect is probably fine. That's what the Python track does. The C++ track expects proper locking and has a test that spawns multiple threads, so chances are without locking this will fail. That's at least somewhat easily testable. We could do the same in C, no matter how we implement this.

parallel-letter-frequency, on the other hand, without parallel processing would be quite boring. And also IMHO be against the spirit of the exercise. After all, it has "parallel" in the name! Some tracks (e.g., Python) explicitly don't want this exercise implemented. I implemented this exercise for the C++ track. To experiment with the performance aspect of the parallelism, it's nice to provide a benchmark students can run locally. For the test runner, we settled on having that only check the correctness of the result, but doing the actual computation sequentially. However, that led to confusion about solutions passing that would actually fail with true parallel execution. So I'd say we should make sure that the experience working locally is as similar as possible to what the online test runner does.

Does the test library support this in a a native way? (Or if we code the tests using the same practices as the implementation, do we risk "giving the game away" too much)

I don't believe the test library has any support for this. But it also doesn't need much. For bank-account, we would manually spawn a couple of threads to call functions in parallel. The student has to implement proper locking, but not create any threads themselves. So except for the library that is used for multithreading the test wouldn't give away much. For parallel-letter-frequency, you wouldn't see anything special in the tests, because all the parallel processing needs to be implemented by the student.

Will the library chosen make the tests or example implementation platform-dependent?

When we go with pthreads, we would be limited to POSIX platforms. For native Windows, one would have to use native Windows threads. However, the makefiles we currently use make things somewhat platform-dependent already, since MSVC wouldn't understand the flags used in there. The documentation suggests to use WSL2 when working under Windows. So there pthreads would work just fine.

The only option I'm aware of that works natively on Windows (with MSVC) is OpenMP. I have used OpenMP pragmas in C++ code. That's much less low level than pthreads and would be similar in spirit to what you do in C++17 with parallel algorithms. However, I think I would find manual thread management more appropriate for a C exercise. I think that's also what the Rust example does: divide the texts into a number of blocks and have a worker thread for each block.

Is there some way to ensure that the submitted implementations are using parallelism rather than just a good sequential implementations?

For bank-account, the parallelism would come from the test. Without proper locking, the test would fail. So that's fairly easy to ensure. For parallel-letter-frequency, on the other hand, I don't see any option (just like the other tracks, they all only test for correctness; so also a sequential implementation would pass).

wolf99 commented 7 months ago

Sounds good @ahans !