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

Day 4 - use types #2

Open
narimiran opened this issue Dec 6, 2018 · 1 comment
Open

Day 4 - use types #2

narimiran opened this issue Dec 6, 2018 · 1 comment

Comments

@narimiran
Copy link

I've seen your Day 4 solution and your (return) types are quite verbose/unreadable. This can be remedied by defining the types and then using their name.

Something like this:

type
  Day = tuple[name: string, times: seq[int]]
  Days = seq[Day]
  Minutes = array[60, string]
  GuardPattern = tuple[date, id: string]
  Sleepiest = tuple[total, guard, mostMinute: int]
  MostMinutes = tuple[totalCount, current: int]


proc parseInput(input:string): (Table[GuardPattern, Minutes], Days) =
  var table = initTable[GuardPattern, Minutes]()
  # etc.


proc findGuardThatSleepsMost(days: Days): Sleepiest =
  var sleepyHead = ""
  let guard = days.map(func(day: Day): string = day[0])
    .deduplicate()
    .map(func(guard: string): Sleepiest =
      let totalMinutes = days
        .filter(func(day: Day): bool = day[0] == guard)
        .map(func(d: Day): seq[int] = d[1])
        .foldl(a.concat(b))
  # etc.
@tradfursten
Copy link
Owner

I hadn't learn about types in day 4 :D Now i use them. We'll see if I get the time to go back and revisit the problem of day 4

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

No branches or pull requests

2 participants