Welcome back for the next exciting installment of Andrew solving Project Rosalind problems! Last time we had the invigorating analysis and solution to Mendel’s First Law. This time, we are going to break down Fibonacci numbers and counting rabbits! But, there will be no hats.
Okay, back to Project Rosalind solutions. Previously we have worked with strands of DNA. We have dealt with parsing and transforming those strands, but this time we are not dealing with DNA specifically. This time we will be dealing with inheritance and how two parents provide traits to their offspring.
This is the third problem in the Project Rosalind Bioinformatics Stronghold series. The original content can be found here. In this problem we will be dealing with a few simple list manipulations, so there should be no need for a deep dive into many of the concepts.
Recently I wrote about writing a more versatile
find in Swift. That was a fun exercise created out of necessity. Additionally, it gave me a little more info on writing functions using Swift generics. Soon after, while I was tooling around on StackOverflow a question came up about stripping some text from a
String using native Swift. I thought “Hey now, that sounds like fun”, so I attempted an answer. Let’s take a look at the two solutions I came up with.
Time for the second problem in the Rosalind bioinformatics track. This time we are tasked with converting a DNA string into an RNA string. Again, I originally wrote this one way but have since decided that wasn’t the best way, so we will cover two solutions.
Games are magical in a number of ways that other media never can be. Books let your imagination take flight and inhabit anything with no restrictions; but, the reader must actively read and envision. Paintings, sculpture, etc. let you observe and project your interpretation. Movies and tv, take the viewer to another world with both sight and sound, but without any way to impact that world. Ah, but games. Games let you go to the universe and actively impact it. And games let you do crazy things you never could in real life.
Today I was working on my game and came up against a little conundrum — I had a collection of things and I wanted to find the first instance that matched some condition, but not need to iterate across the whole collection. Turns out that Swift does not have this built in, from what I could tell. There is (
find)[http://swiftdoc.org/func/find/] in the standard library, but as you’ll notice it takes in a value to find within the collection. Which is great if you are searching for a character in a string, or number in an array. But what about if your array is made up of ranges and you want to find the first range that contains some number? Well the default find is not going to do you any good.
Which is exactly what I was trying to accomplish. So, I wrote my own more Haskell like find. It takes a collection that conforms to the
Sliceable protocol (which an instance of
Array does), a closure that takes an item from that collection and returns a
Bool, and will return the first matching
Index for the collection, or
nil if nothing is found.
The titles in this are getting pretty bad, but hopefully the content is getting better. Let me know what you think in the comments, but only after you have read this post. Please.
Okay, so we’ve covered what is functional programming, and some stuff about data types and type classes in Haskell. Now we should probably get on to actually using that stuff in our programs, with functions.