Poetic Source

Where algorithms meet artistic expression

Learn More About Code Poetry

Featured Poem

Ocean Search

A binary search through ocean depths becomes a meditation on memory and searching, where each comparison draws us deeper into the waters of recollection

@interface OceanSearch : NSObject
@property Depths *depths;
@property Fish *fish;
- (NSInteger)searchWaters:(NSUInteger)low high:(NSUInteger)high;
- (NSInteger)searchDeeper:(NSUInteger)mid than:(NSUInteger)high;
@end
@implementation OceanSearch
- (NSInteger)searchWaters:(NSUInteger)low high:(NSUInteger)high {
NSInteger mid = [depths depthBetween:low and:high]; // dawn breaks on still seas
if (low > high) return NSNotFound; // through deep waters time flows past
if ([fish swimsAtDepth:mid]) // memories appear
return mid; // in these depths I find your trace
return [self searchDeeper:mid than:high]; // seeking in the endless deep
}
- (NSInteger)searchDeeper:(NSUInteger)mid than:(NSUInteger)high {
return [fish compareToDepth:mid] > 0
? [self searchWaters:mid+1 high:high]
: [self searchWaters:low high:mid-1];
}
@end