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

Prefer more concise and cross-language ** operator over Integer.pow/2 #1547

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions exercises/concept/paint-by-number/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- Find the smallest positive number `n` such that 2 raised to the power of `n` is greater than or equal than the number of colors we need to represent.
- Create a recursive function for this.
- Choose a starting bit size of 1. If 2 raised to the power of the bit size is greater than or equal to the color count, we've found our bit size. If not, add 1 to the bit size and check again (recursion).
- Use [`Integer.pow/2`][integer-pow] to raise 2 to a given power.
- Use the [`power operator `**`][power-operator] to raise 2 to a given power.

## 2. Create an empty picture

Expand Down Expand Up @@ -54,4 +54,4 @@
[bitstring-form]: https://hexdocs.pm/elixir/Kernel.SpecialForms.html#%3C%3C%3E%3E/1
[bitstring-matching]: https://hexdocs.pm/elixir/Kernel.SpecialForms.html#%3C%3C%3E%3E/1-binary-bitstring-matching
[type-operator]: https://hexdocs.pm/elixir/Kernel.SpecialForms.html#::/2
[integer-pow]: https://hexdocs.pm/elixir/Integer.html#pow/2
[power-operator]: https://hexdocs.pm/elixir/Kernel.html#**/2
4 changes: 2 additions & 2 deletions exercises/concept/paint-by-number/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PaintByNumber.palette_bit_size(13)
# => 4
```

Note: there is no `log2` function in the Elixir standard library. You will later learn how to use [Erlang libraries][erlang-libraries] from Elixir where you can find this function. Now, solve this task with recursion and the [`Integer.pow/2`][integer-pow] function instead.
Note: there is no `log2` function in the Elixir standard library. You will later learn how to use [Erlang libraries][erlang-libraries] from Elixir where you can find this function. Now, solve this task with recursion and the [power operator `**`][power-operator] instead.

## 2. Create an empty picture

Expand Down Expand Up @@ -113,4 +113,4 @@ PaintByNumber.concat_pictures(picture1, picture2)
[paint-by-number]: https://en.wikipedia.org/wiki/Paint_by_number
[binary-file]: https://en.wikipedia.org/wiki/Binary_file
[erlang-libraries]: https://exercism.org/tracks/elixir/concepts/erlang-libraries
[integer-pow]: https://hexdocs.pm/elixir/Integer.html#pow/2
[power-operator]: https://hexdocs.pm/elixir/Kernel.html#**/2
2 changes: 1 addition & 1 deletion exercises/concept/paint-by-number/.meta/exemplar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule PaintByNumber do
end

defp do_palette_bit_size(color_count, bits \\ 1) do
if Integer.pow(2, bits) >= color_count do
if 2 ** bits >= color_count do
bits
else
do_palette_bit_size(color_count, bits + 1)
Expand Down
Loading