Coding challenge: Force non-equality - runtime

I’m curious if anyone would be interesting in giving and trying an occasional coding challenge (perhaps a new tag or category could be made if it gets popular). These would not be ones like Exercism has or so, but strictly challenges to try to solve language-specific tasks that you may never run across in real-life. Let’s do a simple task as an example:

Force non-equality - runtime

Given this code:

defmodule Testing do
  def f() do
    # Put 1-expression
  end

  def test() do
    false = ( f() == f() )
    true
  end
end

Fill in the # Put 1-expression here with code to make the test pass where calling Testing.test() returns true.

7 Likes

4 posts were split to a new topic: Details about Coding Challenges threads/tag

:erlang.monotonic_time

2 Likes

Yep yep. :slight_smile:

There is still a much shorter way, without calling into :erlang too, what is it? ^.^

1 Like

System.unique_integer

1 Like

make_ref

1 Like

fn x -> x end

Not sure this isn’t more or less make_ref when all is said and done.

1 Like

This was indeed the shortest that I could come up with when I posted it too. :slight_smile:

Ah, I’d not thought of that one but I’d bet it would work too!

Ditto too. :slight_smile:

There are still other simple ones too that I can think of. ^.^

2 Likes

If we’re golfing this for the fewest characters. and don’t mind abusing syntax, I have a 4 character solution :slight_smile:

& &1

props to @bbense for the idea

2 Likes

Oh that is brilliant! ^.^

1 Like

When I tried that one yesterday (OTP 19.2, Elixir 1.4.0) I got a match error, so that doesn’t work.

2 Likes

This code challenge is making me have impure thoughts. :laughing:

3 Likes

Lol, yes, yes you can indeed do impure in Elixir. :wink:

I like to give myself little challenges like this, then try to see how many ways I can come up with to both code-golf it and break the language. ^.^

1 Like

The weird thing about anonymous functions, is that each definition creates a new anonymous function object. But if you assign an anonymous function to a variable, or compile a module that contains it in one of its functions, then this will only create one anonymous function object, and so it will be equal to itself.

3 Likes

It would be great to have a place with language specific challenges, so every one can collaborate.

1 Like

True, just recently I added ocaml and rust to an Elixir Ports benchmark on a github repo recently. I like the test to see how things go. ^.^

1 Like