Baklava in Objective C

Published on 23 December 2024 (Updated: 23 December 2024)

Welcome to the Baklava in Objective C page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

#import <Foundation/Foundation.h>

// Source:
// https://stackoverflow.com/questions/260945/create-nsstring-by-repeating-another-string-a-given-number-of-times
@interface NSString (Baklava)
- (NSString *) repeatString: (NSUInteger) times;
@end

@implementation NSString (Baklava)
- (NSString *) repeatString: (NSUInteger) times {
    return [
        @"" 
        stringByPaddingToLength: [self length] * times
        withString:self startingAtIndex: 0
    ];
}
@end

int main(int argc, const char * argv[]) {
    NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];

    int i;
    for (i = -10; i <= 10; i++) {
        int numSpaces = abs(i);
        int numStars = 21 - 2 * numSpaces;
        printf(
            "%s%s\n",
            [[@" " repeatString: numSpaces] UTF8String],
            [[@"*" repeatString: numStars] UTF8String]
        );
    }

    [pool drain];
    return 0;
}

Baklava in Objective C was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.