Onor.io

Onor.io

Hacker Rank And Elixir

So I was just working through some of the materials over at HackerRank and I can’t quite figure out what they’re doing. I mean they give you a template

defmodule Solution do
end

And you have to write the code inline in the module, like this:

defmodule Solution do
   IO.puts("Hello World")
end

I can’t figure out what it’s doing to get that code to work. It’s not legal Elixir syntax (or is it?) so what’s the trick? I’m not trying to learn anything from HR because I’d like to think I have a good grasp of Elixir already. This strikes me as a poor resource for anyone trying to learn Elixir though.

Most Liked

joaoevangelista

joaoevangelista

Well it is legal, but it will be executed during compilation, not something you can easily assert.

They don’t give you the name of the function and which parameters it should have? It is in neither the tests provided? (I don’t remember if they provide some).

If you like to learn solving these puzzles I prefer Codewars. If not a great resource to hands on learning is Exercism

Last Post!

ambareesha7

ambareesha7

Again I submitted a Hackerrank challenge called “Reverse a list”
submitted code is here:

defmodule Solution do
  def receive do
      IO.read(:all)
      |> String.trim
      |> String.split("\n")
      |> rev()
      |> Enum.map(& IO.inspect(String.to_integer(&1)))
  end
  def rev(list), do: rev(list, [])
  def rev([], acc), do: acc
  def rev([h | t], acc), do: rev(t, [h | acc])
end
Solution.receive()

Where Next?

Popular in Discussions Top

AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20142 166
New
sergio
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages. It also goes on to call Elix...
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18634 126
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
shishini
I think this twitter post and youtube video didn’t get as much attention as I hoped I am still new to Elixir, so can’t really judge ...
New

Other popular topics Top

ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement