-
Notifications
You must be signed in to change notification settings - Fork 253
DNA Proj #412
base: master
Are you sure you want to change the base?
DNA Proj #412
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Cell+mutator.h | ||
// DNK | ||
// | ||
// Created by evgen on 11/13/12. | ||
// Copyright (c) 2012 evgen. All rights reserved. | ||
// | ||
|
||
#import "Cell.h" | ||
|
||
@interface Cell (mutator) | ||
|
||
+(int) getRandIndex; | ||
-(void) mutate:(int) percent; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Cell+mutator.m | ||
// DNK | ||
// | ||
// Created by evgen on 11/13/12. | ||
// Copyright (c) 2012 evgen. All rights reserved. | ||
// | ||
|
||
#import "Cell+mutator.h" | ||
|
||
@implementation Cell (mutator) | ||
|
||
-(void) mutate:(int)percent { | ||
//array with random numbers to check if the new number repeats | ||
NSMutableArray *repeatCheckArray = [NSMutableArray array]; | ||
|
||
for (int i=1; i<percent; ++i){ | ||
|
||
int randindex = [Cell getRandIndex]; | ||
if ([repeatCheckArray containsObject:[NSNumber numberWithInteger:randindex]]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не вижу где идёт добавление использованных индексов в массив repeatCheckArray |
||
--i; //if this number was generated again the new iteration | ||
} | ||
else //else we will change this character with new one | ||
[[self DNA] replaceObjectAtIndex:randindex withObject:[Cell getRandomCharacter]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь еще надо добавить использованный индекс в массив repeatCheckArray, как писали выше. |
||
} | ||
|
||
} | ||
//get random index for changing characters in array | ||
+(int) getRandIndex{ | ||
int x = arc4random() % 99 + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. магические числа... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нумерация индексов NSMutableArray начинается с 0, а не с 1. Поэтому у вас 1-й элемент цепочки ДНК никогда не будет мутировать. |
||
return x; | ||
} | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Cell.h | ||
// DNK | ||
// | ||
// Created by evgen on 11/9/12. | ||
// Copyright (c) 2012 evgen. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface Cell : NSObject { | ||
NSMutableArray *_DNA; | ||
} | ||
|
||
@property NSMutableArray *DNA; | ||
|
||
-(id)init; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. объявление init в этом интерфейсе не нужно, по сколько оно уже есть в интерфейсе супер класса NSObject |
||
//get random object type NSString for the array | ||
+(NSString*)getRandomCharacter; | ||
|
||
-(int) hammingDistance: (Cell*) number; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Cell.m | ||
// DNK | ||
// | ||
// Created by evgen on 11/9/12. | ||
// Copyright (c) 2012 evgen. All rights reserved. | ||
// | ||
|
||
#import "Cell.h" | ||
|
||
@implementation Cell | ||
|
||
//Array object initialization | ||
-(id) init{ | ||
self = [super init]; | ||
|
||
_DNA = [[NSMutableArray alloc] init]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. создание массива вне блока гарантирующего успех вызова [super init] же |
||
_DNA = [NSMutableArray arrayWithCapacity:100]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут второе создание массива, первое тогда надо убрать |
||
|
||
if(self) | ||
for(int i=1;i<=100;i++) //fill the array with random characters | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. опять магические константы (везде по проекту). понятно конечно, что они значат, но с любым ростом проекта - это есть зло. |
||
[_DNA addObject:[Cell getRandomCharacter]]; | ||
|
||
return self; | ||
|
||
} | ||
|
||
-(int)hammingDistance:(Cell*)number{ | ||
int count=0; | ||
|
||
for(int i=0;i<100;i++){ | ||
//compare two arrays | ||
if(!([(NSString*)[[self DNA] objectAtIndex:i] isEqualToString:[[number DNA] objectAtIndex:i]])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не уверен что нужно приведение типа. правда нужно? |
||
count++; | ||
|
||
} | ||
|
||
return count; | ||
} | ||
|
||
|
||
+(NSString*)getRandomCharacter{ | ||
|
||
switch(random()%4){ | ||
case 0: | ||
return @"A"; | ||
case 1: | ||
return @"T"; | ||
case 2: | ||
return @"G"; | ||
} | ||
return @"C"; | ||
} | ||
|
||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// | ||
// Prefix header for all source files of the 'DNK' target in the 'DNK' project | ||
// | ||
|
||
#ifdef __OBJC__ | ||
#import <Foundation/Foundation.h> | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. | ||
.\"See Also: | ||
.\"man mdoc.samples for a complete listing of options | ||
.\"man mdoc for the short list of editing options | ||
.\"/usr/share/misc/mdoc.template | ||
.Dd 11/9/12 \" DATE | ||
.Dt DNK 1 \" Program name and manual section number | ||
.Os Darwin | ||
.Sh NAME \" Section Header - required - don't modify | ||
.Nm DNK, | ||
.\" The following lines are read in generating the apropos(man -k) database. Use only key | ||
.\" words here as the database is built based on the words here and in the .ND line. | ||
.Nm Other_name_for_same_program(), | ||
.Nm Yet another name for the same program. | ||
.\" Use .Nm macro to designate other names for the documented program. | ||
.Nd This line parsed for whatis database. | ||
.Sh SYNOPSIS \" Section Header - required - don't modify | ||
.Nm | ||
.Op Fl abcd \" [-abcd] | ||
.Op Fl a Ar path \" [-a path] | ||
.Op Ar file \" [file] | ||
.Op Ar \" [file ...] | ||
.Ar arg0 \" Underlined argument - use .Ar anywhere to underline | ||
arg2 ... \" Arguments | ||
.Sh DESCRIPTION \" Section Header - required - don't modify | ||
Use the .Nm macro to refer to your program throughout the man page like such: | ||
.Nm | ||
Underlining is accomplished with the .Ar macro like this: | ||
.Ar underlined text . | ||
.Pp \" Inserts a space | ||
A list of items with descriptions: | ||
.Bl -tag -width -indent \" Begins a tagged list | ||
.It item a \" Each item preceded by .It macro | ||
Description of item a | ||
.It item b | ||
Description of item b | ||
.El \" Ends the list | ||
.Pp | ||
A list of flags and their descriptions: | ||
.Bl -tag -width -indent \" Differs from above in tag removed | ||
.It Fl a \"-a flag as a list item | ||
Description of -a flag | ||
.It Fl b | ||
Description of -b flag | ||
.El \" Ends the list | ||
.Pp | ||
.\" .Sh ENVIRONMENT \" May not be needed | ||
.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 | ||
.\" .It Ev ENV_VAR_1 | ||
.\" Description of ENV_VAR_1 | ||
.\" .It Ev ENV_VAR_2 | ||
.\" Description of ENV_VAR_2 | ||
.\" .El | ||
.Sh FILES \" File used or created by the topic of the man page | ||
.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact | ||
.It Pa /usr/share/file_name | ||
FILE_1 description | ||
.It Pa /Users/joeuser/Library/really_long_file_name | ||
FILE_2 description | ||
.El \" Ends the list | ||
.\" .Sh DIAGNOSTICS \" May not be needed | ||
.\" .Bl -diag | ||
.\" .It Diagnostic Tag | ||
.\" Diagnostic informtion here. | ||
.\" .It Diagnostic Tag | ||
.\" Diagnostic informtion here. | ||
.\" .El | ||
.Sh SEE ALSO | ||
.\" List links in ascending order by section, alphabetically within a section. | ||
.\" Please do not reference files that do not exist without filing a bug report | ||
.Xr a 1 , | ||
.Xr b 1 , | ||
.Xr c 1 , | ||
.Xr a 2 , | ||
.Xr b 2 , | ||
.Xr a 3 , | ||
.Xr b 3 | ||
.\" .Sh BUGS \" Document known, unremedied bugs | ||
.\" .Sh HISTORY \" Document history if command behaves in a unique manner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
получается мутируют (percent-1) элементов, а не percent