ios - Storing functions in an array and applying them to an array of numbers -
I have prototyped an algorithm in Python of my iOS game, and I would have to rewrite the ObjC actually, my There is a board of 16 numbers, and I should loop three numbers through each number and the four functions I am using (add, subtract, multiply, exponentiate). 1 + 2 + 3, 2 * 3-4, 3 ^ 4-5, 9-4 ^ 3, etc., but without the operation (first operation is always done first).
Would I like this to be an overview of how this can be implemented in objective C, in particular, what is the equivalent of an array of work in Objective-C? Is it an easy way to implement it with selectors? What is the best structure to use for loops with numbers? Array of The purpose of creating an array of functions- The most convenient way to use blocks is to use: Since it is to arithmetic on NSInteger s,
int s,
NSArray /
NSMutableArray of
NSNumbers ?
Random import as random = 0 maximum = 9 max_target = 20 max_to_calculate = 100 drt multiplication (x, y): return x * y def exponent (x, y): return x * Y def plus (x, y): return x + y def subtract (x, y): return x - y function_array = [multiply, exponate, add, subtract] board = [rand.randint (min, max) i For the board on the xchange (0, 16)] for dict_of_frequencies = {}: B in the board: for the first_fun in the function_arre: first_first = first_fone (A, B) in the board: function_array another function For: Last_reference = second_fone, C) if the last_start is not in digit_of_frequency: dict_of_frequencies [final_digital] = 0 dict_of_frequencies [last_right]] = =
typedef NSIn teaser (^ Arithmetic Blak ) (NSiEtiger, NSINtega); ArithmeticBlock add = ^ NSInteger (NSInteger x, NSInteger y) {return x + y; }; Arithmetic Block All = ^ NSINtegaer (NSITGER X, NSINTG Y) {Return X - Y; }; NSArray * operation = @ [addition, sub]; Since
NSNumber s, it would be best to consider the value of the board such as
NSInteger In a simple array, the
@ (board value) gives you
NSNumber .
Comments
Post a Comment