Programming Exercise #3
In a string of N characters, calculate the frequencies of repeated patterns, e.g., given "AUGCCCGTAUACGTA", one would get CGTA:2, CGT:2, GTA:2, CG:2, GT:2, TA:2, AU:2, CC:2. You do not need to display the information, only get the data in a format from which it can be extracted (hopefully in a pattern that is of order less than the algorithm). You may assume that only the letters A-Z will be used to make the given string.
It may help to review Programming Exercises #1 and #2. Remember, the goal is to make this as efficient as possible with graal script. Your algorithm will be ranked first by big-O notation, then by runtime speed. |
Do we need to find every pattern possible, or just ones specified?
For example, findAllPatterns( n ) or something like findNumber( n, pattern ) |
Assuming that the algorithm should find the number of occurrences of a string in another string. Which it shouldn't.
PHP Code:
PHP Code:
PHP Code:
|
Okay, I have mine finished. It takes about 5 seconds to run (go figure!) but it gets the right answer, at least from what I have seen.
PHP Code:
The script is very inefficient and slow, but it works ... NOTE: You will need to change the [] in the format to a percent sign, it won't let me post without giving me a bad request error. Look for this line: echo( format( "String: []s, Occurances: []s", rc[0], rc[1] ) ); PHP Code:
Also, if a mod wants to delete my last post in this thread they can, it won't let me edit it or delete it anymore for some reason, gives a Bad Request error. |
Quote:
Quote:
|
PHP Code:
|
I have updated the guidelines slightly.
|
Quote:
|
Quote:
|
No comment on what I posted?
You've irritated me. |
How about making Programming Exercise #4 something that we normal mortals stand a chance at? :whatever:
|
Not much to comment. The code and output dump should speak for themselves.
PHP Code:
PHP Code:
|
Quote:
|
Quote:
e: The new standard set by DrakilorP2P, O(n²) @Ziro: Will keep that in mind. ;) |
Quote:
Increased speed of script: PHP Code:
|
All times are GMT +2. The time now is 11:23 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.