Fl4m3Ph03n1x

Fl4m3Ph03n1x

I am doing some exercises while learning Elixir using Exercism.io.
Now, my objective is to do all exercises, extras included. This should give me a good grasp of the power of the language.

However I am having trouble. I don’t quite understand what some exercises want me to do, but I refuse to skip them either. One of these exercises is the following:

Introduction

There are 10 types of people in the world: Those who understand binary, and those who don’t.

You and your fellow cohort of those in the “know” when it comes to binary decide to come up with a secret “handshake”.

1 = wink
10 = double blink
100 = close your eyes
1000 = jump


10000 = Reverse the order of the operations in the secret handshake.

Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.

Here’s a couple of examples:

Given the input 3, the function would return the array [“wink”, “double blink”] because 3 is 11 in binary.

Given the input 19, the function would return the array [“double blink”, “wink”] because 19 is 10011 in binary. Notice that the addition of 16 (10000 in binary) has caused the array to be reversed.

use Bitwise (or div/rem)

If you use Bitwise, an easy way to see if a particular bit is set is to compare the binary AND ( &&& ) of a set of bits with the particular bit pattern you want to check, and determine if the result is the same as the pattern you’re checking.

Example:

Flags: 0b11011 Check: 0b11010

Flags &&& Check: 0b11010 (All checked bits are set)

Another:

Flags: 0b11011 Check: 0b10110

Flags &&& Check: 0b10010 (Third bit not set)

Question

Could someone help me understand why 11 translates to ["wink", "double blink"] instead of translating to ["wink", "wink"] ? ( it has two 1, right ? )

I know I am missing something rather basic but I just can see what.

Showing Posts 19 to 10

NobbZ

NobbZ

It’s fully open source.

Check out Exercism · GitHub

kip

kip

ex_cldr Core Team

This is another one that is quite fun with binary pattern matching :slight_smile:

defmodule Secret do
  def handshake(number) when is_integer(number) do
    handshake(<< number :: size(5) >>)
  end

  @code ["jump", "close your eyes", "double blink", "wink"]
  def handshake(<< reverse :: size(1), jump :: size(1), close :: size(1), double :: size(1), wink :: size(1) >>) do
    shake =
      [jump, close, double, wink]
      |> Enum.zip(@code)
      |> Enum.reduce([], fn
          {0, _}, acc -> acc
          {1, item}, acc -> [item | acc]
        end)

    # Since Enum.reduce/3 returns the list in reverse order,
    # we only reverse if the reverse bit is not set :-)
    if reverse == 1, do: shake, else: Enum.reverse(shake)
  end
end

iex> Secret.handshake 3
["wink", "double blink"]
hex> Secret.handshake 0b00111
["close your eyes", "double blink", "wink"]
iex> Secret.handshake 0b10111
["wink", "double blink", "close your eyes"]
Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

So Exercism.io is a community driven effort ( by the Elixir community ? )
If so perhaps I could help as well? There is always strength in numbers.

peerreynders

peerreynders

The way the information is presented in the example makes no sense to me. “Recycling” the bits and pieces that are there leads me to this “best guess”:

iex(1)> import Bitwise
Bitwise
iex(2)> flags = 0b11011
27
iex(3)> check = 0b11010
26
iex(4)> (flags &&& check) == check # true - because all the necessary bits are set
true
iex(5)> flags = 0b11011
27
iex(6)> check = 0b10110
22
iex(7)> (flags &&& check) == check # false - because third bit is not set
false
iex(8)> 
NobbZ

NobbZ

Yes, we are on par with that. At least now after the relaunch. But as I said, there is a lot to do after the relaunch to identify exercises that do not suite the new product and community goals anymore. Even more work is to be done to rephrase them or to decide to remove them completely.

I hope I find some time later today, after the kids are in bed, to at least skim some exercises to find some examples of “pesky clients” and then draft a first issue that I can post on github to actually raise the attention of Katrina Owen to the problem and get some discussion around the topic started.

Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

I also feel like that, but for the sake of learning the language I try to power through as much as possible.

@NobbZ Wonderful insight, however this is not Exercism.io’s purpose. It’s purpose is not to simulate pesky clients it is to give you objective exercises so you can learn the language.

@peerreynders So, this is confusing to me.
I fail to see how doing 0b11011 &&& 0b10110 which results in 18, is supposed to tell me that the 3rd bit is not set and how that affects the exercise.

NobbZ

NobbZ

If you are lucky and work for an employer that actually asks back… Congratulations. I’ve seen it differently a lot of times even though, I am in the lucky situation, that I’m developing on a core product that is mostly experimental, and as such requirements are discovered by myself and formalized by the team before they get implemented in future sprints.

peerreynders

peerreynders

Doesn’t even come close:

“We want this.”
“Why do you think you need that?”

… which sooner or later leads to the discovery that the actual problem needs a completely different solution.

NobbZ

NobbZ

Sometimes the assignments are purposely vague, it’s a bit in the spirit of the customer that only ever tells what he really needs a week after the deadline :wink:

But yes, I liked this under the old exercism, but the new should clean up with those. This exercises are scary and not in the warm and welcoming spirit the new exercism should have.

peerreynders

peerreynders

Those are the type of constraints that I like to see explicitly stated, otherwise more time is spent on trying to figure out what the intended problem is rather than solving the problem.

(I realize I’m in no position to complain given this is a volunteer effort - I just find the same to apply in other avenues.)

Where Next? Top

Trending in Chat/Questions Top

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews