diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..0eba6af4 Binary files /dev/null and b/.DS_Store differ diff --git a/dna_1.xcodeproj/project.pbxproj b/dna_1.xcodeproj/project.pbxproj new file mode 100644 index 00000000..50e76e73 --- /dev/null +++ b/dna_1.xcodeproj/project.pbxproj @@ -0,0 +1,255 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 0ED9C11616E8D1E2009525B7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ED9C11516E8D1E2009525B7 /* Foundation.framework */; }; + 0ED9C11916E8D1E2009525B7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C11816E8D1E2009525B7 /* main.m */; }; + 0ED9C11D16E8D1E3009525B7 /* dna_1.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0ED9C11C16E8D1E3009525B7 /* dna_1.1 */; }; + 0ED9C12516E8D215009525B7 /* Cell.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C12416E8D215009525B7 /* Cell.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 0ED9C11016E8D1E2009525B7 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + 0ED9C11D16E8D1E3009525B7 /* dna_1.1 in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 0ED9C11216E8D1E2009525B7 /* dna_1 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = dna_1; sourceTree = BUILT_PRODUCTS_DIR; }; + 0ED9C11516E8D1E2009525B7 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 0ED9C11816E8D1E2009525B7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 0ED9C11B16E8D1E2009525B7 /* dna_1-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dna_1-Prefix.pch"; sourceTree = ""; }; + 0ED9C11C16E8D1E3009525B7 /* dna_1.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = dna_1.1; sourceTree = ""; }; + 0ED9C12316E8D215009525B7 /* Cell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cell.h; sourceTree = ""; }; + 0ED9C12416E8D215009525B7 /* Cell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Cell.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 0ED9C10F16E8D1E2009525B7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 0ED9C11616E8D1E2009525B7 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 0ED9C10916E8D1E2009525B7 = { + isa = PBXGroup; + children = ( + 0ED9C11716E8D1E2009525B7 /* dna_1 */, + 0ED9C11416E8D1E2009525B7 /* Frameworks */, + 0ED9C11316E8D1E2009525B7 /* Products */, + ); + sourceTree = ""; + }; + 0ED9C11316E8D1E2009525B7 /* Products */ = { + isa = PBXGroup; + children = ( + 0ED9C11216E8D1E2009525B7 /* dna_1 */, + ); + name = Products; + sourceTree = ""; + }; + 0ED9C11416E8D1E2009525B7 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 0ED9C11516E8D1E2009525B7 /* Foundation.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 0ED9C11716E8D1E2009525B7 /* dna_1 */ = { + isa = PBXGroup; + children = ( + 0ED9C11816E8D1E2009525B7 /* main.m */, + 0ED9C12316E8D215009525B7 /* Cell.h */, + 0ED9C12416E8D215009525B7 /* Cell.m */, + 0ED9C11C16E8D1E3009525B7 /* dna_1.1 */, + 0ED9C11A16E8D1E2009525B7 /* Supporting Files */, + ); + path = dna_1; + sourceTree = ""; + }; + 0ED9C11A16E8D1E2009525B7 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 0ED9C11B16E8D1E2009525B7 /* dna_1-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 0ED9C11116E8D1E2009525B7 /* dna_1 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 0ED9C12016E8D1E3009525B7 /* Build configuration list for PBXNativeTarget "dna_1" */; + buildPhases = ( + 0ED9C10E16E8D1E2009525B7 /* Sources */, + 0ED9C10F16E8D1E2009525B7 /* Frameworks */, + 0ED9C11016E8D1E2009525B7 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = dna_1; + productName = dna_1; + productReference = 0ED9C11216E8D1E2009525B7 /* dna_1 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 0ED9C10A16E8D1E2009525B7 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0460; + ORGANIZATIONNAME = partisan; + }; + buildConfigurationList = 0ED9C10D16E8D1E2009525B7 /* Build configuration list for PBXProject "dna_1" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 0ED9C10916E8D1E2009525B7; + productRefGroup = 0ED9C11316E8D1E2009525B7 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 0ED9C11116E8D1E2009525B7 /* dna_1 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 0ED9C10E16E8D1E2009525B7 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 0ED9C11916E8D1E2009525B7 /* main.m in Sources */, + 0ED9C12516E8D215009525B7 /* Cell.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 0ED9C11E16E8D1E3009525B7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 0ED9C11F16E8D1E3009525B7 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + SDKROOT = macosx; + }; + name = Release; + }; + 0ED9C12116E8D1E3009525B7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "dna_1/dna_1-Prefix.pch"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 0ED9C12216E8D1E3009525B7 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "dna_1/dna_1-Prefix.pch"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 0ED9C10D16E8D1E2009525B7 /* Build configuration list for PBXProject "dna_1" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 0ED9C11E16E8D1E3009525B7 /* Debug */, + 0ED9C11F16E8D1E3009525B7 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 0ED9C12016E8D1E3009525B7 /* Build configuration list for PBXNativeTarget "dna_1" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 0ED9C12116E8D1E3009525B7 /* Debug */, + 0ED9C12216E8D1E3009525B7 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 0ED9C10A16E8D1E2009525B7 /* Project object */; +} diff --git a/dna_1.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/dna_1.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..8ed079de --- /dev/null +++ b/dna_1.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/dna_1.xcodeproj/project.xcworkspace/xcuserdata/partisan.xcuserdatad/UserInterfaceState.xcuserstate b/dna_1.xcodeproj/project.xcworkspace/xcuserdata/partisan.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..9376e35d Binary files /dev/null and b/dna_1.xcodeproj/project.xcworkspace/xcuserdata/partisan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist new file mode 100644 index 00000000..932727cf --- /dev/null +++ b/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -0,0 +1,20 @@ + + + + + + + diff --git a/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcschemes/dna_1.xcscheme b/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcschemes/dna_1.xcscheme new file mode 100644 index 00000000..5d964b7f --- /dev/null +++ b/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcschemes/dna_1.xcscheme @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcschemes/xcschememanagement.plist b/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..ad5157b9 --- /dev/null +++ b/dna_1.xcodeproj/xcuserdata/partisan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + dna_1.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 0ED9C11116E8D1E2009525B7 + + primary + + + + + diff --git a/dna_1/.DS_Store b/dna_1/.DS_Store new file mode 100644 index 00000000..6afad2e1 Binary files /dev/null and b/dna_1/.DS_Store differ diff --git a/dna_1/Cell.h b/dna_1/Cell.h new file mode 100644 index 00000000..d06d3807 --- /dev/null +++ b/dna_1/Cell.h @@ -0,0 +1,23 @@ +// +// cell.h +// dna_1 +// +// Created by Partisan on 07.03.13. +// Copyright (c) 2013 partisan. All rights reserved. +// + +#import + +@interface Cell : NSObject +-(id)init; +-(void)print; +-(id) getGeneAtIndex:(unsigned int) index; +-(void) setGene:(NSString *)gene AtIndex: (unsigned int) index; +-(id)getDNA; +-(int)hammingDistance:(Cell *) c; + +@end + +@interface Cell (Mutation) +-(void)mutate:(int) percent; +@end; diff --git a/dna_1/Cell.m b/dna_1/Cell.m new file mode 100644 index 00000000..2012078b --- /dev/null +++ b/dna_1/Cell.m @@ -0,0 +1,99 @@ +// +// cell.m +// dna_1 +// +// Created by Partisan on 07.03.13. +// Copyright (c) 2013 partisan. All rights reserved. +// + +#import "Cell.h" + +@implementation Cell{ + NSMutableArray * dna; + NSArray * posibleGene; + int chromosomesAmt; + unsigned long seed; + +} + +-(id)init{ + self = [super init]; + chromosomesAmt = 100; + + posibleGene = [[NSArray alloc] initWithObjects:@"A", @"T", @"G", @"C", nil ]; + seed = [posibleGene count]; + + if (self){ + dna = [[NSMutableArray alloc] init]; + + for (int i = 0; i < chromosomesAmt; i++){ + + [dna addObject:[posibleGene objectAtIndex:(arc4random() % seed)]]; + + } + + } + return self; +} +-(void)print{ + + NSLog(@"%@ ", [self getDNA]); +} +-(int)hammingDistance:(Cell *) c{ + int result=0; + for (int i = 0; i < chromosomesAmt; i++){ + if ( [self getGeneAtIndex:i] != [c getGeneAtIndex:i]) + result++; + } + return result; +} + +-(id)getGeneAtIndex: (unsigned int) index{ // гетер генов + if (index <= chromosomesAmt) + return [dna objectAtIndex:index]; + return nil; +} + +-(id)getDNA{ // возвращает всю последовательность генов + NSMutableString * result = [[NSMutableString alloc] init]; + for (id gene in dna) + [result appendString:gene]; + return result; +} + +-(void) setGene:(NSString *)gene AtIndex: (unsigned int) index;{ + [dna setObject:gene atIndexedSubscript:index]; +} + +@end + +@implementation Cell (Mutation) + + +-(void)mutate: (int) percent{ + percent=percent%100; //на случай если передадут больше 100% + + int numberMutGene = chromosomesAmt * percent / 100; + id newGene; + NSMutableArray *uniq = [[NSMutableArray alloc] init]; + int curentlyMutGen = 0; + + for (int i = 0; i < numberMutGene; i++){ + + do{ + curentlyMutGen = arc4random() % chromosomesAmt; + }while ([uniq doesContain:[self getGeneAtIndex:curentlyMutGen]]); + + [uniq addObject:[[NSString alloc] initWithFormat:@"%i", curentlyMutGen, nil ] ]; + do { + newGene = [posibleGene objectAtIndex:(arc4random() % seed)]; + } while ([self getGeneAtIndex:curentlyMutGen ] == newGene); + + + + + [self setGene:newGene AtIndex:curentlyMutGen]; + } +} + +@end \ No newline at end of file diff --git a/dna_1/dna_1-Prefix.pch b/dna_1/dna_1-Prefix.pch new file mode 100644 index 00000000..18f7160f --- /dev/null +++ b/dna_1/dna_1-Prefix.pch @@ -0,0 +1,7 @@ +// +// Prefix header for all source files of the 'dna_1' target in the 'dna_1' project +// + +#ifdef __OBJC__ + #import +#endif diff --git a/dna_1/dna_1.1 b/dna_1/dna_1.1 new file mode 100644 index 00000000..a596b073 --- /dev/null +++ b/dna_1/dna_1.1 @@ -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 07.03.13 \" DATE +.Dt dna_1 1 \" Program name and manual section number +.Os Darwin +.Sh NAME \" Section Header - required - don't modify +.Nm dna_1, +.\" 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 \ No newline at end of file diff --git a/dna_1/main.m b/dna_1/main.m new file mode 100644 index 00000000..b34b6922 --- /dev/null +++ b/dna_1/main.m @@ -0,0 +1,37 @@ +// +// main.m +// dna_1 +// +// Created by Partisan on 07.03.13. +// Copyright (c) 2013 partisan. All rights reserved. +// + +#import +#import "Cell.h" + +int main(int argc, const char * argv[]) +{ + + @autoreleasepool { + + Cell * myCell1 = [[Cell alloc] init]; + Cell * myCell2 = [[Cell alloc] init]; + + [myCell1 print]; + [myCell2 print]; + + NSLog(@"Hamming distance before mutation: %i", [myCell1 hammingDistance:myCell2]); + + [myCell1 mutate:10]; + [myCell2 mutate:10]; + + + [myCell1 print]; + [myCell2 print]; + + NSLog(@"Hamming distance after mutation: %i", [myCell1 hammingDistance:myCell2]); + + } + return 0; +} +