Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment2 #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

caryhumphries
Copy link

Cary Humphries
47237948

@pragdave
Copy link
Contributor

5 minutes late.

I'll grade this, but…

sum2a = your_anonymous_function(1, 2)
#sum2a = your_anonymous_function(1, 2)

sum2a = fn(a, b) -> a + b end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

sum2b = your_anonymous_function(1, 2)
#sum2b = your_anonymous_function(1, 2)

sum2b = &(&1 + &2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

sum3a = your_anonymous_function(1, 2, 3)
#sum3a = your_anonymous_function(1, 2, 3)

sum3a = fn(a, b, c) -> sum2a.(a, sum2a.(b,c)) end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

sum3b = your_anonymous_function
#sum3b = your_anonymous_function

sum3b = &(sum2b.(&1, sum2b.(&2, &3)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

create_adder = your_anonymous_function(1)
#create_adder = your_anonymous_function(1)

create_adder = fn(x) -> (fn(y) -> x + y end) end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10


#def list_equal . . . "your code"

def list_equal([],[]) do true end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4

Same comment here. On line 130, you could test the two heads are equal with

def list_equal([h|t1], [h|t2]), do: list_equal(t1, t2)
def list_equal(_, _), do: false

@@ -149,7 +180,43 @@ defmodule Ex03 do
Think a little about a nice way to lay this code out.
"""

def won . . . "your code"
#def won . . . "your code"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0

You were on the right track. Here's my solution:

  def won(position) do
    case position do
      { a, a, a,
        _, _, _,
        _, _, _ } -> a

      { _, _, _,
        a, a, a,
        _, _, _ } -> a

      { _, _, _,
        _, _, _,
        a, a, a } -> a

      { a, _, _,
        a, _, _,
        a, _, _ } -> a

      { _, a, _,
        _, a, _,
        _, a, _ } -> a

      { _, _, a,
        _, _, a,
        _, _, a } -> a

      { a, _, _,
        _, a, _,
        _, _, a } -> a

      { _, _, a,
        _, a, _,
        a, _, _ } -> a

      _ -> false
    end
  end

def reverse . . . "your code"
#def reverse . . . "your code"

def reverse(list), do: reduce(list, [], &[&1 | &2])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

def min . . . "your code"
#def min . . . "your code"

def min(list), do: reduce(list, &(if &1 < &2 do &1 else &2 end))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5

def even_odd . . . "your code"


#def even_odd . . . "your code"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants