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

Assignments for updated exercises and new exercises #776

Open
tasxatzial opened this issue Jan 17, 2025 · 13 comments
Open

Assignments for updated exercises and new exercises #776

tasxatzial opened this issue Jan 17, 2025 · 13 comments

Comments

@tasxatzial
Copy link
Member

To avoid duplicate work, assign yourself an exercise that you plan to work on by posting it here.

cc @ErikSchierboom

@tasxatzial
Copy link
Member Author

tasxatzial commented Jan 17, 2025

update for pig-latin ✅
update for acronym ✅
update for change ✅

@ErikSchierboom
Copy link
Member

ErikSchierboom commented Jan 18, 2025

  • update for yacht
  • update for sublist
  • update for space age

@ErikSchierboom
Copy link
Member

ErikSchierboom commented Jan 18, 2025

  • new: knapsack
  • new: food chain

@ErikSchierboom
Copy link
Member

ErikSchierboom commented Jan 18, 2025

  • new: alphametics
  • new: killer-sudoku-helper
  • new: game-of-life
  • new: state-of-tic-tac-toe

@tasxatzial
Copy link
Member Author

tasxatzial commented Jan 18, 2025

update for hamming ✅
update for series ✅
update for binary-search
update for collatz-conjecture ✅
update for rna-transcription ✅

@tasxatzial
Copy link
Member Author

tasxatzial commented Jan 23, 2025

new: bowling

@tasxatzial
Copy link
Member Author

tasxatzial commented Jan 23, 2025

I'll pass on the bowling exercise for now, as i'm a bit confused by the instructions, as usual.

update for transpose ✅
new: connect (fingers crossed) ✅

@tasxatzial
Copy link
Member Author

tasxatzial commented Jan 30, 2025

update for matching-brackets ✅
update for atbash-cipher ✅
update for grains ✅
update for pythagorean-triplet ✅

@tasxatzial
Copy link
Member Author

I'm trying to update binary-search now. The current tests check for (thrown-with-msg? Throwable #"not found"). The specs suggest an error with msg "value not in array", but also mention that we should use what's idiomatic for the language.

Any idea what would be idiomatic here? Throwing exception does not look like the correct approach here, and i'm not even able to find an appropriate exception type. What do you think about returning -1? This looks more reasonable to me.

@tasxatzial
Copy link
Member Author

tasxatzial commented Feb 1, 2025

I checked Java's built-in Arrays.binarySearch and it's returning (-(insertion point) - 1) when not found.

See https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#binarySearch-int:A-int-

This looks reasonable, but it also feels like a bit overkill, as the insertion point might not be clearly communicated by the tests. It can be mentioned in an append file, though.

@ErikSchierboom
Copy link
Member

I think throwing an exception is wrong, and not finding a value is not something exceptional.

What do you think about returning -1?

That's fine, but I think that is mostly done in languages that don't allow for returning a nullable integer. What about just using nil? After all, that's the value for "there's nothing here.".

@tasxatzial
Copy link
Member Author

I have considered using nil because it is indeed the value for something that's not there. But the problem is that it just can't be used in every case where we are trying to find something that's not there. It's so tricky to use properly, that i prefer to stay away from it.

I was reading a book that talked about it. There was a chapter with title: nil should be the absence of only a few values. It said, and i quote the book:

We cannot consider a function that returns nil in isolation; we have to look at the downstream functions to make sure they interpret our nil correctly

Some examples from the book:

  • For conj, cons, and nth, nil is the absence of a seq (e.g. (conj :nil :x) returns (x)
  • For count, nil is an empty collection (e.g. (count nil) returns 0)

and so on.

It did go into some lengthy explanation about what happens if nil is misused (returning it instead of throwing errors). It also suggested that we should avoid using the common idiom (when x). This just returns nil, but it's difficult for other functions to interpret it properly. The conclusion was:

If nil can be coerced to an empty collection, we should do that. If not, we should throw an error. Anything else sows needless confusion.

Obviously, using nil in this exercise isn't going to be causing any issues, and we also don't always have to throw errors. But my preference would be to avoid using it completely, if possible.

@ErikSchierboom
Copy link
Member

Then I would prefer to use -1. That's quite a common pattern used in other languages

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

No branches or pull requests

2 participants