[48in24 Exercise] [03-19] Allergies

This issue is a discussion for contributors to collaborate in getting ready to be featured in 48in24. Please refer to this forum topic for more info.


We will be featuring Allergies from Mar 19 onwards.

Staff jobs

These are things for Erik/Jeremy to do:

  • ☐ Check/update exercise in Problem Specifications
  • :ballot_box_with_check: Create + schedule video

Community jobs

For each track:

  • Implement Allergies
  • Add approaches (and an approaches introduction!) for each idiomatic or interesting/educational approach.
  • Add video walkthroughs (record yourself solving and digging deeper into the exercise).
  • Highlight up to 16 different featured exercises (coming soon)

Existing Approaches

You can use these as the basis for approaches on your own tracks. Feel free to copy/paste/reuse/rewrite/etc as you see fit! Maybe ask ChatGPT to translate to your programming language.

  • vec-on-new (rust)
  • vec-when-requested (rust)

Track Statuses

You can see an overview of which tracks have implemented the exercise at the #48in24 implementation status page.

I’ll take care of Ballerina, CFML, CoffeeScript, and D.

2 Likes

I think Elm is a featured language for Allergies, so I will try and add the approaches. I might not have enough time to get it done though …

2 Likes

For this exercise’s video, I currently have these solutions and taling points. If you know more or better versions of these, let me know.

  1. Gleam: type for allergen and use pattern matching, list uses allergic_to

Custom type for allergen and use pattern matching to assign type

  1. JavaScript: dictionary for mapping

Use a dictionary for mapping allergens to their bit scores

  1. Ruby: index determines allergen value

Have the index determine the allergen value

  1. Clojure: bit test function and hash set, allergic_to uses list

Use a function to test if bit is set and allergic_to reuses list of allergens

  1. C#: define enum as a flags enum (easy testing of bits)

Also show other ways in which to define the bit masks

  1. Nim: automatically convert number to set of enum

Use cast to convert a number of an enum set

  1. Python: iteratively subtract enum values

Subtract the enum values in reverse

I’ve added the approaches for Elm, PR here if people are interested:

3 Likes

The Raku documentation has an example well suited to this exercise:

https://docs.raku.org/language/typesystem#Typing_Enums

My solution has borrowed from this. The enums are given the appropriate values using a lazy infinite sequence. An ACCEPTS method has been mixed in with the enum and can be called on any of the enum values to check the score matches. The smartmatch operator is a shortcut to ACCEPTS.

1 Like

Adding to the V track

1 Like

Since Pyret is live, I guess I should add allergies there.

1 Like

lol - the pain of a new track now needing all the 48in24 exercises :grin:

1 Like

Happily, the sqlite track is also new, complete with Allergies already :clap:.

I’ll watch with interest to see if anyone tries to add Zebra Puzzle to that (I’m not volunteering).

1 Like

And one without bitwise operators to boot. I’m about to learn some math for the first time in two decades. :sweat_smile:

1 Like

Catching up on Red exercises to port :slight_smile:

1 Like

Clojure sync

Edit: Please do not merge immediately after opening

@tasx Did you know, that you can mark a Pull Request as a draft if you want to add something later?

Thanks, no, I did not know that.

However, I don’t think that a draft PR would be of any help here. The PR is always automatically closed, effectively blocking any further actions. I can’t mark it as a draft, and if I push a new commit, it won’t show up. Even if I mark it as a draft, someone might get the wrong idea and not open it because they won’t see any updates.

Also, I’m not sure if there’s still an issue with not being able to open a PR if someone pushes a new commit while it is closed.

In any case, I’m not pushing anything until it’s reopened.

If you push a new commit I think it does show up. The branch still updates when you push to it. I might be wrong, but I’m pretty sure that’s the case because we often have issues reopening if people have force-pushed.

Regardless, I’ve reopened and marked as draft :slight_smile:

1 Like

Thanks

There was a very recent case where someone pushed an extra commit to their PR, and it didn’t show up until it was reopened. The same thing happened to me with a previous commit, and in my case, I believe I had force-pushed. This ended up being a mistake because it created a mismatch between the hash shown on the PR and the commit on my fork. I had to do some weird tricks before Bobbi was able to reopen it.

If the PR wasn’t closed, it wouldn’t be an issue. But with closed PRs, I’m not taking any chances. I’d rather just leave a comment :slight_smile:

1 Like