Think different(ly)
Get out of your rut and learn new ways to think.
| defmodule Center do | |
| require Integer | |
| def center(string_list) do | |
| size_max = string_list |> Enum.max_by(&String.length/1) |> String.length() | |
| Enum.map(string_list, fn x -> show(x, size_max) end) | |
| end | |
| defp show(string, size_max) do |
Local: Sala 8 do DAINF (ramal 4747)
Reserve seu horário comentando abaixo com seu nome, dia e horário! O(A) primeiro(a) a reservar fica com o horário!
| weighted = fn choices -> | |
| max = Enum.reduce(choices, 0, &(&2 + elem(&1, 1))) | |
| Enum.reduce_while(choices, Enum.random(1..max), fn | |
| {item, weight}, acc when acc <= weight -> {:halt, item} | |
| {_item, weight}, acc -> {:cont, acc - weight} | |
| end) | |
| end | |
| weighted.([{"likely", 9}, {"not likely", 1}]) |
| play :C | |
| sleep 0.5 | |
| play :D | |
| sleep 0.5 | |
| play :E | |
| sleep 1 | |
| play :G | |
| sleep 1 | |
| play :G | |
| sleep 1 |
| -module(first). | |
| -export([double/1, treble/1, mult/2, area/3, square/1]). | |
| mult(X,Y) -> | |
| X*Y. | |
| double(X) -> | |
| mult(2,X). | |
| treble(X) -> | |
| mult(3,X). | |
| area(A,B,C) -> |
| -module(logic). | |
| % In the previous video step on pattern matching we saw two ways of defining | |
| % “exclusive or”. Give at least three others. You might find it useful to | |
| % know that: | |
| % =/= and == are the operations for inequality and equality in Erlang; | |
| % not is the Erlang negation function; and, | |
| % and and or are the Erlang conjunction and disjunction (infix) operators. | |
| -export([exclusive_or_1/2,exclusive_or_2/2,exclusive_or_3/2,exclusive_or_4/2, | |
| exclusive_or_5/2, max_three/3, how_many_equal/3, test_exclusive_or_1/0]). |
| % a mdoule to calculate areas, perimeters and bits | |
| % https://www.futurelearn.com/courses/functional-programming-erlang/3/steps/488101/assignment/submissions/new | |
| -module(geometry). | |
| -export([area/1, test_area/0]). | |
| -export([perimeter/1, test_perimeter/0]). | |
| -export([enclose/1, test_enclose/0]). | |
| -export([bits/1, test_bits/0]). | |
| -export([bits_direct_recursive/1, test_bits_direct_recursive/0]). | |
| -export([bits_tail_recursive/1, test_bits_tail_recursive/0]). |
| defmodule BMI do | |
| def compute(height_in_m, weight_in_kg) do | |
| weight_in_kg/(height_in_m*height_in_m) | |
| end | |
| def test_bmi() do | |
| 22.395413419331717 = BMI.compute(1.83, 75) | |
| 37.10937499999999 = BMI.compute(1.60, 95) | |
| 80 = BMI.compute(1.10, 100) |
| -module(exercise). | |
| -export([product/1, test_product/0]). | |
| -export([direct_product/1, test_direct_product/0]). | |
| -export([max_list/1, test_max_list/0]). | |
| -export([direct_max_list/1, test_direct_max_list/0]). | |
| product(X) -> | |
| product_aux(X, 1). |