Commit 32ee0394 authored by Nikolay Petrachkov's avatar Nikolay Petrachkov

Add Advent_of_code_2018#Day_05 part 1 in Elixir.

parent 66fd4014
# Used by "mix format"
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
# The directory Mix will write compiled artifacts to.
# If you run "mix test --cover", coverage assets end up here.
# The directory Mix downloads your dependencies sources to.
# Where 3rd-party dependencies like ExDoc output generated docs.
# Ignore .fetch files in case you like to edit your project deps locally.
# If the VM crashes, it generates a dump, let's ignore it too.
# Also ignore archive artifacts (built via "mix").
# Ignore package tarball (built via "mix").
# Polymer
**TODO: Add description**
## Installation
If [available in Hex](, the package can be installed
by adding `polymer` to your list of dependencies in `mix.exs`:
def deps do
{:polymer, "~> 0.1.0"}
Documentation can be generated with [ExDoc](
and published on [HexDocs]( Once published, the docs can
be found at [](
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.
# You can configure your application as:
# config :polymer, key: :value
# and access this configuration in your application as:
# Application.get_env(:polymer, :key)
# You can also configure a 3rd-party app:
# config :logger, level: :info
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
# import_config "#{Mix.env()}.exs"
This diff is collapsed.
defmodule Polymer do
@moduledoc """
Removes units with opposite polarization
(sequence of letters with opposite capitalizetion).
def start(filename) do
|> Stream.flat_map(&String.split(&1, "\n", trim: true))
|> Stream.flat_map(&String.to_charlist/1)
|> Stream.chunk_every(5000)
|> Task.async_stream(&Polymer.compute/1)
|> Enum.reduce([], fn {:ok, part}, acc -> acc ++ [part] end)
|> List.to_string()
|> String.to_charlist()
|> compute()
|> Enum.count()
def compute([h | t]), do: compute(t, h, [])
def compute([h | []], Nil, seen), do: compute([], Nil, seen ++ [h])
def compute([h | t], Nil, seen), do: compute(t, h, seen)
def compute([h | t], prev, seen) do
case abs(h - prev) == 32 do
true -> compute(seen ++ t, Nil, [])
false -> compute([h | t], Nil, seen ++ [prev])
def compute([], _prev, seen), do: seen
defmodule Polymer.MixProject do
use Mix.Project
def project do
app: :polymer,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps()
# Run "mix help" to learn about applications.
def application do
extra_applications: [:logger]
# Run "mix help deps" to learn about dependencies.
defp deps do
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "", tag: "0.1.0"},
This diff is collapsed.
defmodule PolymerTest do
use ExUnit.Case
test "computes polymer" do
assert Polymer.start("test/test.txt") == "dabCBAcaDA"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment