« first day (2396 days earlier)      last day (253 days later) » 

3:00 PM
Welcome to APL Quest 2021-1! Today's quest is Are You a Bacteria?:
> A DNA string is composed of the letters ‘A’,’C’,’G’ and ‘T’. The GC-content of a DNA string is given by the percentage of the symbols in the string that are either ‘C’ or ‘G’. Very small discrepancies in GC-content can be used to distinguish species; for instance, most bacteria have a GC-content significantly higher than 50%.
> Write a function that:
• has a right argument that is a non-empty character vector representing a DNA string.
• returns the percentage of GC-content in the string.
 
(100×(+/'CG'∊⍨⊢)÷≢)
 
I think you can simplify that a bit.
 
⍨ wasn't necessary.
Was still left over trying to remove the ()
 
Right. How about tying the argument to ?
What about combining the summation with the division?
 
(100×(+/⊢∊∘'CG')÷≢)
but it is not correct
 
3:09 PM
Just ∊∘'CG'
 
that gives a domain error
 
(100×(+/∊∘'CG')÷≢)
 
ah yes, sorry
 
oh yay I actually could make it this time
I had 100×≢÷⍨1⊥∊∘'CG' which is of course the same thing as the ones above but spelled differently
 
@Adám Or equivalent ly 100×≢÷⍨+⌿⍤∊∘'CG'
ah, forgot about +⌿ ≡ 1⊥
 
3:15 PM
Any time you have a reduction over a scalar application on a vector, you can use an inner product.
 
so 100×(∊∘'CG')+.÷≢ ?
 
:)
 
@Silas Yes, but why parenthesise a simple derived function?
 
Because I wrote that one first working out how to place the inner product. 100×≢+.÷⍨∊∘'CG' otherwise
 
Right.
 
3:21 PM
although feel hesitant about +.÷⍨
 
But why swap at all?
 
Because that failed tests - 100×≢+.÷∊∘'CG' should have returned 100 with ('GCGCGCGCCCGGGGCCG') as right argument
 
100×∊∘'CG'+.÷≢ is fine, right?
 
Exactly!
Beautiful, isn't it?
 
what was the rationale with the challenge requiring a percentage?
 
3:23 PM
ahh, thanks Ruben!
 
yes!
 
I think ∊∘'CG'+.÷≢ would've been an even more beautiful piece of code
 
@RubenVerg Just more stuff to do
 
i guess that's a valid reason:)
I wonder, did anybody in challenge times do some ugly iterative solution?
 
I think I can look it up. Hang on.
 
3:27 PM
I made this, uh, abomination, for fun
{0=≢⍺:100×÷/⍵⋄(1↓⍺)∇⍵+1,⍨(⊃⍺)∊'CG'}∘0 0
 
Oh no. 😭
 
why elegance when i m p e r a t i v e do job
 
{100×(+/1pco⎕A⍳⍵)÷≢⍵⊣⎕CY'dfns'}
 
what is {⍵}∘0 0 ?
 
@Richard it's a dyadic fn
 
3:31 PM
@Richard A monadic function that returns 0 0 no matter the argument.
@RubenVerg No, but I found this gem: {(1+.=⌊⍟⎕A⍳⍵)×100÷⍴⍵}
 
Percent←AreYouABacteria DNA
 Percent←0
  :For C :In DNA
    :If (C='C')∨(C='G')
     Percent+←100÷≢DNA
    :EndIf
  :EndFor
cursed enough?
 
OK, I think we need to stop before this turns into an ALGOL forum.
 
Back to Basic :)
 
@Adám this is a weirdly clever solution, I suppose
 
See you next week for 2021-2: Index-Of Modified!
 
3:33 PM
thanks!
 
@Adám ohh I get it now
that's, uh, odd
thanks :)
 
3:45 PM
@Adám as usual won't sure if I'll be here, so ⍳×⍳≤≢⍤⊣
surely could be made much better, don't really have time tho
 
⍳×∊⍨ ?
Kinda annoying how and work in opposite directions
Btw, maybe we should mark our solutions as spoilers before the Quest officially begins?
 
4:46 PM
@Adám Surely APLGOL is allowed :)
 
 
7 hours later…
11:18 PM
@RubenVerg Oh, nice. I completely missed the inner product opportunity here.
 

« first day (2396 days earlier)      last day (253 days later) »