#
Phase 1 Review

Sorry I was busy this weekend and didnβt get a chance to respond.

I am excited to see how others approached the problems. Thank you @Moody for compiling the problems.

Here is some commentary on my solutions.

##
1: Counting DNA Nucleotides

```
fn β +/'ACGT'β.=,
```

This was an eye-opening experience for me. Using the outer product to build a relationship table

```
dna β 'AGCTTTTCATTCTGAC'
'ACGT' β.= dna
1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0
0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1
0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0
```

and then summing

```
+/ 'ACGT' β.= dna
3 4 2 7
```

was a perfect example of βThinking with Arraysβ. The `,`

was to catch an edge case.

##
2: Attack of the Mutations!

```
fn β +/β
```

This solution creates a boolean mask where the arrays are not equal and then sums. Pretty straightforward.

##
3: Uniquely Qualified

```
fn β (~,~β¨)β₯,
```

From what I understood this question is asking for the βExclusive Orβ of the arguments.

The Without function `A ~ B`

provided the elements of `A`

without the elements of `B`

. For the solution, I would need to reverse `B ~ A`

as well. The Commute operator `β¨`

flips the arguments. Finally, I join the lists together with `β₯,`

. I am not so comfortable with the use of the Over operator `β₯`

but it worked!

##
4: In the Long Oneβ¦

```
fn β β/0,β’Β¨β€ββ¨β,
```

My approach here came from experimenting with applying the partition function to a binary array.

```
b β 1 1 1 0 1 1 0 0 1 1 1 1 0
(ββ¨) b
βββββββ¬ββββ¬ββββββββ
β1 1 1β1 1β1 1 1 1β
βββββββ΄ββββ΄ββββββββ
```

Now I wanted to count each box

```
(β’Β¨β€ββ¨) b
3 2 4
```

and then take the maximum

```
(β/β’Β¨β€ββ¨) b
4
```

##
5: Stairway to Heaven (with apologies to Led Zeppelin)

```
fn β β½βββ΄β'β'Β¨ββ³
```

My approach here was to generate a sequence of boxes from 1 to n, and then reshape it to look correct.

```
(β΄β'β'Β¨ββ³) 5
βββ¬βββ¬ββββ¬βββββ¬ββββββ
βββββββββββββββββββββ
βββ΄βββ΄ββββ΄βββββ΄ββββββ
```

Here `β΄β'β'`

is applied to each number from iota `β³`

. The last bit opens the boxed array and rotates it.

```
(β½βββ΄β'β'Β¨ββ³) 5
β
ββ
βββ
ββββ
βββββ
```

##
6: Pyramid Scheme

```
fnββββ½βββ¨(β.ββ¨ββ³0βΒ―1+Γβ2)
```

My thought process here was to generate a matrix, flip it around and then take the minimum. The phrase `0βΒ―1+Γβ2`

came from the question and calculates the appropriate size for the matrix. Next up was to generate a matrix. I decided to use the outer product with a minimum `β`

as the function to be applied.

```
(β.ββ¨ββ³0βΒ―1+Γβ2) 3
1 1 1 1 1
1 2 2 2 2
1 2 3 3 3
1 2 3 4 4
1 2 3 4 5
```

Then rotate it

```
β½ββ(β.ββ¨ββ³0βΒ―1+Γβ2) 3
5 4 3 2 1
4 4 3 2 1
3 3 3 2 1
2 2 2 2 1
1 1 1 1 1
```

Finally, take the minimum of these two matrices

```
(βββ½βββ¨(β.ββ¨ββ³0βΒ―1+Γβ2)) 3
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1
```

##
7: Just Golfing Around

```
fn β (β,/)((β’β’β€/+βΏΓ·β’)Β¨β³β¨β₯,ββ³ββ’)
```

This problem caused me a lot of difficulties. My initial approach was to do a similar technique to problem 4 where I use the partition function.

```
t β 68 71 71 73
ββ¨ t
ββββ¬ββββββ¬βββ
β68β71 71β73β
ββββ΄ββββββ΄βββ
```

but the issue here is I need to group the places not the value of the score. Luckily the function argument is always sorted so we can use iota `β³`

to generate a list of places

```
(β³β’) t
1 2 3 4
```

and I will also use the dyadic for of iota which gives me the index of the first occurrence of each score

```
β³β¨ t
1 2 2 4
```

These two functions are joined by a partition `β`

to form the separate rankings

```
(β³β¨ββ³ββ’) t
βββ¬ββββ¬ββ
β1β2 3β4β
βββ΄ββββ΄ββ
```

Next, I wanted to find the average of each box.

```
((+βΏΓ·β’)Β¨β³β¨ββ³ββ’) t
1 2.5 4
```

but the problem was I needed to replicate the average for tied places. The replicate function `/`

was used along with `β’`

.

```
((β’β’β€/+βΏΓ·β’)Β¨β³β¨β₯,ββ³ββ’) t
βββ¬ββββββββ¬ββ
β1β2.5 2.5β4β
βββ΄ββββββββ΄ββ
```

It turns out the slash symbol is tricky because sometimes it can be a function and other times it can be an operator. In this case, I appended a right tack to the slash to force it to be a function rather than an operator.

All that is left is to concatenate the values and unbox the result

```
(β,/)((β’β’β€/+βΏΓ·β’)Β¨β³β¨β₯,ββ³ββ’) t
1 2.5 2.5 4
```

##
8: Letβs Split!

```
fn β {nββΊ(-β1(β/β£β³β¨(β¬β,β’)))β΅β(nββ΅)(nββ΅)}
```

For this problem, we were asked to split a list based on the first occurrence of an element from the left array in the right array.

My first task was to find the location where to split the array. For this, the dyadic β³ was very useful.

```
(β/ 'do' β³β¨ 'Hello World')-1
4
```

Then it was just a matter of taking and dropping the same amount

```
(4 β 'Hello World')(4 β 'Hello World')
ββββββ¬ββββββββ
βHellβo Worldβ
ββββββ΄ββββββββ
```

The rest of the solution was catching edge cases, and train building.

##
9: An Average Window (or a Windowed Average)

```
fn β {nβ(1+2ΓβΊ)βnΓ·β¨n+/(βΊ/1ββ΅),β΅,(βΊ/Β―1ββ΅)}
```

For this problem, I wanted to construct an array with the appropriate padding and then perform the windowed average.

I would need `βΊ`

extra copies on each end of my array to accommodate a window size of `1+2ΓβΊ`

.

```
2 { (βΊ/1ββ΅),β΅,(βΊ/Β―1ββ΅) } β³6
1 1 1 2 3 4 5 6 6 6
```

With such an array constructed, the windowed sum was performed and divided by the window size to calculate the average

```
2 fn β³ 6
1.6 2.2 3 4 4.8 5.4
```

##
10: Separation Anxiety

```
fn β {β,/ βΊ {βΊ} @ {0=6|β½β³β’β΅}1β(2 β β΅)}
```

My approach here was to split up the input by using a partition enclose. The left argument of the dyadic form represents the number of dividers to place between each element.

```
{1β(2 β β΅) }'10000000'
βββ¬β¬ββ¬β¬ββ¬β¬ββ¬β¬ββ¬β¬ββ¬β¬ββ¬β¬ββ
β1ββ0ββ0ββ0ββ0ββ0ββ0ββ0β
βββ΄β΄ββ΄β΄ββ΄β΄ββ΄β΄ββ΄β΄ββ΄β΄ββ΄β΄ββ
```

With this setup, now we need a function to insert our separators where they belong. We want our separator to be placed at every 6th position, starting from the right, so I reversed an iota and performed a modulo.

```
{0=6|β½β³β’β΅} {1β(2 β β΅)} '100000000'
0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0
```

With a boolean mask established all we need to pass to the `@`

operator is the separator and join the result

```
',' {β,/ βΊ {βΊ} @ {0=6|β½β³β’β΅}1β(2 β β΅)} '100000000'
100,000,000
```