Commit c2a41dde authored by Nikolay Petrachkov's avatar Nikolay Petrachkov

Add Advent_of_code_2018#day_02 part 1 in Elixir.

parent e63d6cdb
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
checksum-*.tar
# Checksum
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `checksum` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:checksum, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/checksum](https://hexdocs.pm/checksum).
# 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 :checksum, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:checksum, :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"
ivyhczwokexltwhsfamqprbnuy
ivjhcjdokexltwwsfamqpabnuy
ivjhczdokebltwgsfydqprbnuy
ivjhcadokexftogsfamqprbnuy
idjhczdokexltwgsfacqprbnuh
ivjhgzookexltwgsfamqjrbnuy
uvjhctdokexltwosfamqprbnuy
ivrhczdokexltwhzfamqprbnuy
ivjhczuxkexltwgsfamqprbney
ivjhczdokemltwgsfadnprbnuy
ifjhczdokexltwgsfamqprbkuf
ivjhkzdokltltwgsfamqprbnuy
ivjuczdhkexltwgsfamqprtnuy
ivjhjzdxkexltwgsfapqprbnuy
ivlhczdoxexltwgsfamqprgnuy
ivjhczdoknxltwgssamqsrbnuy
ivjhczdokexltwgswadqprbruy
ivjhczdokexthwgsfampprbnuy
uvjhczrozexltwgsfamqprbnuy
ivolczdokexltwgsffmqprbnuy
ivjhczibkexltwgsfamoprbnuy
ivjhczdokefltmgsfamqprbouy
ivjhczdobexltngsfamsprbnuy
ivjhczdokexltwvsfxqqprbnuy
dvjhczdokexucwgsfamqprbnuy
kvjhszkokexltwgsfamqprbnuy
ivjhczdokexrtegsfamqprbnus
ivjhctdokexltwglgamqprbnuy
ivjhczdozexutwgsfamqdrbnuy
ivjhczqokemltwgsfakqprbnuy
uvjhczdokexlqwgsfadqprbnuy
ivjhczdohexltwglffmqprbnuy
izjhczdokexltwgsfamqprbsqy
iajhczdokwxltwgjfamqprbnuy
ivjfczdokexllwgslamqprbnuy
ivjhczdoyexltwgsfamqdrbnxy
ivjhczdokekwtwssfamqprbnuy
ivjhcodokexltwgsfamqirxnuy
ihjhhzdokexltwgsfamqlrbnuy
ivjdpzdokexltwfsfamqprbnuy
ivjhcpdokexltwgsfamqqrbruy
qvjhcziokexltwgsfamqprbnny
ivohczdomexltwgsfkmqprbnuy
ivjhczhokhxlywgsfamqprbnuy
ivjhczdokexltwgmffmqprbruy
ivjhczdokqxltwgcfamqprbnyy
ivjhczdokepltwgsfamcprbnay
ivjhczdokexltwgseamqpmbnua
ivjzczdokexltwgszamqplbnuy
ivjhczpokexltwgvfgmqprbnuy
idjhczdokexltwgsxamqprbndy
ivjhczdxkexltwgcgamqprbnuy
ivjhczdckexatpgsfamqprbnuy
ivjrczdorexltwgsfamqprbnvy
ivjoczdokexltwgswamqprbtuy
iylhczdokexltwgsfamqpxbnuy
imxhczdokkxltwgsfamqprbnuy
ivvhczdoktxltwgsfamaprbnuy
ivyhczdokexltwhsfayqprbnuy
ivjhcrdokexltegsfamqprbnum
rvjhezdokexltwgsoamqprbnuy
ivjzczdokexlbwgsfkmqprbnuy
ivjhczdokelltwgsyamqprbnoy
ixjhczdorexltwgsfamqprbuuy
ivjhczpokexdtwglfamqprbnuy
ivjhczdokexltwgfgamcprbnuy
ikjhczdokexltwgsfamqirbnux
ivjhczdopjxltwgsfamqprbnny
ivchczdokexltwgniamqprbnuy
ivjhczdooeqltwgsfamqprbniy
ivjhcldonexltwgbfamqprbnuy
ixjhczdokehltwgsfamqprbnuf
ivjhczdckefltwgsfamqppbnuy
ivjhczdoqrxltwgsfamqprbnun
ivjhczdokcxltwgmfarqprbnuy
ivjhcziorexltqgsfamqprbnuy
ivjhwzdokexltwgnfamqprbcuy
ivjhczdoqexltwgsfazqprunuy
iijhczdokexltwgsyamqprbnug
ivjhczdokexltwgxfamhprbnry
ivjhczdakexltwgsfaeqlrbnuy
ivjhqzdokehltwgsfampprbnuy
ivjhczdokexltwlsfpmyprbnuy
ivjhfzdoktxltwgsfamzprbnuy
ivlhvzdokexltwgsvamqprbnuy
ivjhczdbkexltwgsaamqprfnuy
ivahcedokexltigsfamqprbnuy
cvjhczdokexltwgsfamapibnuy
ivjhczkokbxltwgsfbmqprbnuy
pvjuczdnkexltwgsfamqprbnuy
iyjhczdckexotwgsfamqprbnuy
ivjhzzdokvxltwgsfamqprbnuo
ivjhczdobexltwgsxamqprbnry
ivjhczdokexltwgsfaprprbnub
ivjhczdokexltwgofarqprbkuy
ivjhczdokexltwgbfymqprbnhy
ibjhczdokexltwgsfkmqpvbnuy
ivjhczdzkexlywgsfacqprbnuy
hvdhczdokexltwglfamqprbnuy
ivjhczdokexrtwgsfamqprbsuh
ivjhczhokexltngsfamqpjbnuy
ivjhcsjokexltwgsfaeqprbnuy
ivjmczdokexltmgsfamqpbbnuy
wvjhczdokexltwgsfamkpkbnuy
icjhpzdoaexltwgsfamqprbnuy
ivjmczdhkexltwgsfzmqprbnuy
ivjhczdokexytwgsfamqprbwug
ikjhczdjkexljwgsfamqprbnuy
ivjvcdmokexltwgsfamqprbnuy
ivjhazdorixltwgsfamqprbnuy
ivchczdokexltwgsfamzprenuy
ivjcczdokexlttgsfamqpmbnuy
ibchgzdokexltwgsfamqprbnuy
ivjhczdokepltwgsfamqpeenuy
ivjnwzdokexlrwgsfamqprbnuy
ivjhczdokexitwgsfadqlrbnuy
icjhcrdokexltwgsfamqkrbnuy
ivngczdokexltwgsfamqprbyuy
ivjhuudokexlvwgsfamqprbnuy
ivjhczdnkexltwgsfhmqpxbnuy
itjhczdokexltwvsfamgprbnuy
ivjhcddokexltwgsfakqprbnny
ivjhuzdojexltwfsfamqprbnuy
idjhczdokexltwgsfamqukbnuy
ivjhczdokexlzigsfamqprbngy
ivjwczdokexltwgufamqprbnuo
iijhczdokexltwfsfadqprbnuy
ivjhczdukexdtwgsfamqpsbnuy
idjhczdokexllwgssamqprbnuy
zvjhczdokexrtwgsfamqplbnuy
ivphczdofexltwgefamqprbnuy
ivhhczdokexlpwgsjamqprbnuy
ivjhczdovexltwgsfamqprhnuj
ivjhczdoklxltwgseamqprlnuy
ivjhcqdokexltngsfamqprdnuy
ivjhczdoifxltagsfamqprbnuy
izjhczdokexltwjsramqprbnuy
psjhczdokexlgwgsfamqprbnuy
ivjhcadokexltwgsfsmqwrbnuy
ivjhczdokexltwgsfawqiibnuy
ivjhczkokexhtwgsfamqprbnuk
ivjhcmdukexltwgsfamvprbnuy
ivjlczdokexltwgsfamquibnuy
ivjhczdokexntwgyfamqprbniy
ivjhczdokexltwlsfafqprbnuc
ivjhczdosexltrtsfamqprbnuy
ivjhcznokexbtwgsfafqprbnuy
ivwtczdotexltwgsfamqprbnuy
ivjhvzdokexltigsoamqprbnuy
ivjhcmdokexltwasfamqirbnuy
ivthczdokexltwgsfaydprbnuy
ivjhwzdskexltwgsfamqprbnus
icjhczdosuxltwgsfamqprbnuy
ivjhczdokexltwgstamqbrmnuy
iejhczuoktxltwgsfamqprbnuy
ivjhczdokeqltwgskamqprbniy
ivjhlzdokexltugsfamqprbpuy
iwjqczdckexltwgsfamqprbnuy
ivjhwzdokexluwgsfxmqprbnuy
ivjhczdokexltwgwfwmqprbguy
gvjhczkokexltwgsfgmqprbnuy
ivjhczdoyexlhwgsfamqprbnoy
cvjhczdokexltwgsfomqprinuy
vvmhczdokexltwgsfamqprbnun
vvjhczdokexltwgsftmfprbnuy
ivkhckdokhxltwgsfamqprbnuy
iyjhczdkkexltjgsfamqprbnuy
ivlhczdokexltwgsfamqyrbhuy
tvjhmzdokexltwgsfamqorbnuy
ivjhczdokexltwvsfamqprbnxi
ivjhczdowexltwgswamqerbnuy
wvjiczdomexltwgsfamqprbnuy
ivjpizdokexltwgvfamqprbnuy
ivjhuzdokexlzwgspamqprbnuy
ivjhczdokeyltwgkfamqprdnuy
jvjhczdokexlnwgsfamqirbnuy
ivjheidokexltwvsfamqprbnuy
mvjhczdokexltwgsfamqyrsnuy
ivjhazdykexltwgsramqprbnuy
ivjkcodokexltwgsxamqprbnuy
ikjhczdoktxltwgpfamqprbnuy
ivjhyzdfkexmtwgsfamqprbnuy
ivohczdokexltugsfamqprynuy
ivjkczdqkexltwgshamqprbnuy
ivjhczdokexltwgskamqynbnuy
icjhczdokexltwgofamrprbnuy
ivjhlzdokealtwgsfamqsrbnuy
ivehczdybexltwgsfamqprbnuy
ovjhczdokexltwgsfamqirbnuo
ivjoczdokexltwgsfamqurbnty
ivjmczdokexltwgsfrmqprnnuy
ivjhczdowpxltwgbfamqprbnuy
ivjhczdokexltwfsfamqkrgnuy
ivjhwzdokexltwgsfavqprbnuq
jvjhczdokexltwgsiamqprbnny
ivjhlzdouexltwfsfamqprbnuy
ivjhczdokexltwgsfamqbrbnlv
iwjhczdokexltwgsfapqprbnqy
idjhczdokexltwgsaamqrrbnuy
ivjhjzdopepltwgsfamqprbnuy
ivjmczdokejltwgsfamqpbbnuy
ivjhczdokexltwgsuamdprvnuy
injhczdokexltwgefamqurbnuy
iujhczdokexltwgsaamqjrbnuy
ivjhczdokexltwgvfaaqprbnly
ivehczdokexltwgsfamqppbnui
ivxhczdodexltwgsfamqplbnuy
ivjhczfokexltwgsfamqpwbauy
ivjhcztwkexhtwgsfamqprbnuy
ivjeczdokexltygsfmmqprbnuy
ivjhchdokexltwgsmameprbnuy
ivkhczdoklxltwggfamqprbnuy
ivjhczdzkexltwhsfamqprjnuy
ivjhcedokeultngsfamqprbnuy
ivjhczdokexvtwgseabqprbnuy
ivjhczdooexltlgsfamqpibnuy
ivjgczvosexltwgsfamqprbnuy
ivlhczwokexltwgsfamqmrbnuy
lvjhczdokexutwgsfamrprbnuy
ivahczdokexpdwgsfamqprbnuy
ivjhcznokexltwhsfamqpnbnuy
ivjhczdpkyxltwgbfamqprbnuy
ivjhnzdokexltwgsftmqprinuy
ivihczdokexltnhsfamqprbnuy
ivjhcbdokevltwgsfamqprbauy
hgjoczdokexltwgsfamqprbnuy
dvjhczdckexltwgsfamqpybnuy
ivjhcadokesltwgsfsmqwrbnuy
ivjhwzdokexlttgsfamqprbney
ivjhcidokexltwgofamqfrbnuy
ivokwzdokexltwgsfamqprbnuy
ivjiczdokexltwgsfaqqarbnuy
ivjhczdokexqtwfsfamgprbnuy
ivjhczdokealtwgsfamqerbnqy
ivjhczdskexltwgsfamqprznuu
ivjhwzdokexltwjsfdmqprbnuy
ivjhczaokexlzwgsfamqprbnus
ivjhczdokexltwosfamqnrbnux
ivjhczdokexlqwgsfamwprcnuy
ivjhczdqkexltwgswamqpcbnuy
ijjhczdokexnttgsfamqprbnuy
ivjhcedckexltwgsfamqprbnpy
ivjhczdokeyltwgsfamqshbnuy
ivjhczdokexltsgsfamqpmznuy
ivjlczdtkeiltwgsfamqprbnuy
ivjhczdokexltwgsfkmtprbnby
ivjhnzdozexltwgsfamqprbnuc
xqjxczdokexltwgsfamqprbnuy
ivjhczdokeyltwgsfamqnrbnuw
ivjwczgokexltwgsfamvprbnuy
defmodule Checksum do
@moduledoc """
Documentation for Checksum.
"""
@doc """
Hello world.
## Examples
iex> Checksum.compute(["abcdeff"])
1
"""
def main(args) do
{opts, _, _} = OptionParser.parse(
args,
switches: [file: :string, part: :integer],
aliases: [f: :file, p: :part]
)
input_file = File.stream!(opts[:file])
cond do
opts[:part] == 1 ->
input_file |> compute()
# opts[:part] == 2 ->
# input_file |> compute_2()
end
end
def compute(values) do
values
|> Stream.flat_map(&String.split(&1, "\n", trim: true))
|> Stream.flat_map(fn a ->
a
|> String.graphemes()
|> Enum.reduce(%{}, fn a, acc ->
Map.update(acc, a, 1, &(&1 + 1))
end)
|> filter_map(fn _, v -> v > 1 end)
|> Map.values
|> Enum.uniq
end)
|> Enum.reduce(%{}, fn v, acc ->
Map.update(acc, v, 1, &(&1 + 1))
end)
|> Map.values
|> Enum.reduce(&*/2)
|> IO.inspect
end
defp filter_map(map, fun) do
:maps.filter fun, map
end
def compute_2(values) do
end
end
defmodule Checksum.MixProject do
use Mix.Project
def project do
[
app: :checksum,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps(),
escript: escript()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
]
end
defp escript do
[main_module: Checksum]
end
end
defmodule ChecksumTest do
use ExUnit.Case
doctest Checksum
test "calculates demo checksum" do
input_data = ["abcdef\n", "bababc\n", "abbcde\n", "abcccd\n", "aabcdd\n", "abcdee\n", "ababab" ]
assert Checksum.compute(input_data) == 12
end
end
abcdef
bababc
abbcde
abcccd
aabcdd
abcdee
ababab
abcde
fghij
klmno
pqrst
fguij
axcye
wvxyz
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