Last active
January 2, 2016 03:19
-
-
Save vikingosegundo/8243075 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
NSUInteger euclid(NSUInteger a, NSUInteger b) | |
{ | |
while (b > 0) { | |
if (a > b) { | |
a = a - b; | |
} else { | |
b = b - a; | |
} | |
} | |
return a; | |
} | |
NSUInteger recursiveEuclid(NSUInteger a, NSUInteger b) | |
{ | |
if(b == 0) | |
return a; | |
return recursiveEuclid (b, a % b); | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSUInteger first = 1; | |
NSUInteger second = 2; | |
BOOL recursive = NO; | |
if ([[NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding] isEqualToString:@"-r"]) { | |
first = 2; | |
second = 3; | |
recursive = YES; | |
} | |
NSInteger x = [[NSString stringWithCString:argv[first] encoding:NSUTF8StringEncoding] integerValue]; | |
NSInteger y = [[NSString stringWithCString:argv[second] encoding:NSUTF8StringEncoding] integerValue]; | |
if (x < 1 || y < 1) { | |
NSLog(@"Werte aus ℕ mit a, b > 0 erlaubt"); | |
return -1; | |
} | |
NSUInteger ggt = (recursive)? recursiveEuclid(x, y) : euclid(x, y); | |
x = x / ggt; | |
y = y / ggt; | |
NSLog(@"%ld quadratische Stücke (%ld x %ld) mit %ld cm Seitenlänge", x*y, x,y, ggt); | |
if (ggt > 1) { | |
NSLog(@"oder einfach quadratische Stücke mit 1 cm Seitenlänge"); | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
astridskuchenblech: | |
a,b ∈ ℕ\{0} | |
./astridskuchenblech a b | |
./astridskuchenblech -r a b | |
./astridskuchenblech 120 144 | |
./astridskuchenblech -r 120 144 | |
30 quadratische Stücke (5 x 6) mit 24 cm Seitenlänge | |
oder einfach quadratische Stücke mit 1 cm Seitenlänge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment