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

Add Eliud's eggs exercise #694

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Conversation

kahgoh
Copy link
Member

@kahgoh kahgoh commented Oct 31, 2024

This is one of the 48in24 exercises

Copy link
Member

@tasxatzial tasxatzial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind moving its config entry after complex-numbers? There are two PRs open that modify the main config, and merging it as-is will create conflicts in both.

Also, adding 'basics' as a prerequisite would be nice to have.

@tasxatzial
Copy link
Member

tasxatzial commented Nov 3, 2024

@kahgoh Since the instructions mention a bit-count functionality that doesn’t actually exist, I’ve added a small appendix to ensure there’s no confusion.

@kahgoh
Copy link
Member Author

kahgoh commented Nov 3, 2024

Hey @tasxatzial, I just had a look at the instructions.append.md. I thought the note in the instructions is aimed to discourage students from using a function that actually counts the number of 1 bits in the input number (which would solve entire exercise with just one function). For example, in Crystal, Integers have a popcount function, x86-64 assembly has a popcnt instruction and Python has bit_count that does the same. By the way, Java has Integer.bitCount. I think that's what we're trying to discourage them from.

I don't think we need stop students from using the other bitwise operations. For example, another strategy is to use bit shifting (to divide by two) and bitwise & to work out when to increment the count (for example in this C solution or this Python one).

@tasxatzial
Copy link
Member

tasxatzial commented Nov 3, 2024

I see, so a solution that looks like so would be considered ok?

(defn egg-count [number]
  (->> (Integer/toBinaryString number)
       count
       range
       (map #(bit-test number %))
       (filter true?)
       count))

This converts to a binary string (via Java interop), constructs a list from 0 to the number of its digits - 1, maps bit-test over that list to check if the bit at each index is true or false, and finally counts the number of true values.

@tasxatzial
Copy link
Member

tasxatzial commented Nov 3, 2024

Okay, I'll allow the bit-* functions for now and re-evaluate once community solutions start coming in.

Side note: This appears to be a great exercise for exploring different approaches.

@tasxatzial tasxatzial merged commit 587a1e8 into exercism:main Nov 4, 2024
4 checks passed
@kahgoh kahgoh deleted the exercise/eliuds-eggs branch November 4, 2024 13:58
@tasxatzial
Copy link
Member

tasxatzial commented Nov 4, 2024

I’m also thinking that 'don't use bit-count functionality' could easily be interpreted as 'don't use bit-* and count functions,' since bit-count isn't a Clojure function. I'll be monitoring the solutions closely, but I'll most likely add an appendix to prevent confusion.

Then again, mentioning the bit-* functions might make people lean towards using them instead of thinking of alternative ways to solve the problem.

Forum thread:
https://forum.exercism.org/t/eliuds-eggs-instructions-restrictions-are-too-specific/13672

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.

2 participants