Hooks – Run a custom function after purchasing a course / completing an order on LearnPress?

I need to execute a function immediately when someone buys a course or an order completes successfully. The function I'm trying to execute is actually called an API. I don't see a proper LearnPress hook.

It works perfectly when I use "user_register"(when someone registers this fire hook) hook but it doesn't work when i use this "learn_press_confirm_order" hook given by LearnPress.

Do you know that there is some appropriate way I can go about and accomplish this?
Thanks for your time

c – Why is my minimax function not working correctly?

I am creating an AI for a board game known as Reversi / Othello. I have created a minimax function that plays n moves forward for every possible move for each player and chooses the best possible outcome. However, I find that when playing against a player he often makes stupid mistakes (even after including the heuristic) and loses quite often. Is there a problem with logic in my program?
As a note, all the functions included within the minimax function work perfectly fine, I have thoroughly tested them.

float minimax(char **board, int n, int row, int col, char colour, int depth, float alpha, float beta, bool maxPlayer, char *computerColourPtr, char *playColourPtr) {
    //printf("%dn", depth);
    char compMoves(50) = {0};
    char oppMoves(50) = {0};
    char colour2;
    if (maxPlayer) {
        colour = *computerColourPtr;
        colour2 = *playColourPtr;
        }
    else {
        colour2 = *computerColourPtr;
        colour = *playColourPtr;
        }

    char **oldBoard = (char **)malloc(sizeof(char *) * n);
    for (int i = 0; i < n; i++) {
        oldBoard(i) = (char *)malloc(n);
        }
    copyBoard(board, oldBoard, n);
    char **flippedBoard = (char **)malloc(sizeof(char *) * n);
    for (int i = 0; i < n; i++) {
        flippedBoard(i) = (char *)malloc(n);
        }
    copyBoard(oldBoard, flippedBoard, n);
    //printf("Depth: %d. %c at %c%cn", depth, colour, row + 97, col + 97);
    int maxMoves = availableMoves(n, oldBoard, *computerColourPtr, compMoves, false);
    int minMoves = availableMoves(n, oldBoard, *playColourPtr, oppMoves, false);
    //printf("%d %dn", maxMoves, minMoves);
    if (depth == 0 || (maxMoves + minMoves) == 0) {
        int numOfMax = countColour(n, flippedBoard, *computerColourPtr);
        int numOfMin = countColour(n, flippedBoard, *playColourPtr);
        double timeD = ((numOfMax + numOfMin)/(float)(n*n));
        float summation = 0;

        summation += 25.0*timeD*(float)numOfMax/(float)(numOfMax+numOfMin);
        //printf("Avail: %lfn", 0.5*(float)availableMoves(n, flippedBoard, *computerColourPtr, compMoves, false));
        summation += (float)availableMoves(n, flippedBoard, *computerColourPtr, compMoves, false);
        summation -= (float)availableMoves(n, flippedBoard, *playColourPtr, oppMoves, false);
        summation += maxFlipped(n, flippedBoard, *computerColourPtr);
        summation -= maxFlipped(n, flippedBoard, *playColourPtr);
        //summation += timeD*(float)flip(flippedBoard, colour, row, col, n, false);
        //printf("%fn", summation);
        //summation += 1.0*timeD*edgePlaces(row, col, n, colour);
        //printf("%fn", summation);
        //summation += timeD*2.0*(float)((numOfMax+numOfMin)-(n*n)/4)*(numOfMax/(numOfMax+numOfMin));
        //printf("%fn", summation);
        //printf("Corner move: %lfn", 3.0*timeD*(float)location(row, col, n, *computerColourPtr, flippedBoard));
        //summation += 3.0*location(row, col, n, *computerColourPtr, flippedBoard);
        //printf("Depth of blegh. %c at %c%c: %f %c: %d %c: %dn", colour, row+97,col+97, summation, colour, numOfMax, colour2, numOfMin);
        //printBoard(flippedBoard, n);
        return summation;
        }


    if (maxPlayer) {
        float maxEval = -10000;
        float eval1;
        for (int row = 0; row < n; row++) {
            for (int col = 0; col < n; col++) {
                for (int deltaRow = -1; deltaRow <= 1; deltaRow++) {
                    for (int deltaCol = -1; deltaCol <= 1; deltaCol++) {
                        if (checkLegalInDirection(oldBoard, n, row, col, colour, deltaRow, deltaCol)) {
                            copyBoard(oldBoard, flippedBoard, n);
                            flip(flippedBoard, colour, row+97, col+97, n, true);
                            flippedBoard(row)(col) = colour;
                            //printf("Depth of %d. %c at %c%c: %fn", depth, colour, row+97,col+97, maxEval);
                            //printBoard(flippedBoard, n);
                            eval1 = minimax(flippedBoard, n, row, col, colour, depth - 1, alpha, beta, false, computerColourPtr, playColourPtr);
                            maxEval = max(maxEval, eval1);
                            alpha = max(alpha, eval1);
                            //printf("Max: %fn", maxEval);
                            //printBoard(flippedBoard, n);
                            if (beta <= alpha) {
                                row = col = deltaRow = deltaCol = n;
                                break;
                            }
                        }
                    }
                }
            }
        }
    //printf("MAXIMUM: %lfn", maxEval);
    return maxEval;
    }

    else {
        float minEval = 10000;
        float eval2;
        for (int row = 0; row < n; row++) {
            for (int col = 0; col < n; col++) {
                for (int deltaRow = -1; deltaRow <= 1; deltaRow++) {
                    for (int deltaCol = -1; deltaCol <= 1; deltaCol++) {
                        if (checkLegalInDirection(oldBoard, n, row, col, colour, deltaRow, deltaCol)) {
                            copyBoard(oldBoard, flippedBoard, n);
                            flip(flippedBoard, colour, row+97, col+97, n, true);
                            flippedBoard(row)(col) = colour;
                            //printf("Depth of %d. %c at %c%c: %fn", depth, colour, row+97,col+97, minEval);
                            //printBoard(flippedBoard, n);
                            //printBoard(flippedBoard, n);
                            eval2 = minimax(flippedBoard, n, row, col, colour, depth - 1, alpha, beta, true, computerColourPtr, playColourPtr);
                            minEval = min(minEval, eval2);
                            beta = min(beta, eval2);
                            //printf("Min: %fn", minEval);
                            //printf("Depth of %d. %c at %c%c: %fn", depth, colour, row+97,col+97, minEval);
                            //printBoard(flippedBoard, n);
                            if (beta <= alpha) {
                                row = col = deltaRow = deltaCol = n;
                                break;
                            }
                        }
                    }
                }
            }
        }
    //printf("MINIMUM: %lfn", minEval);
    return minEval;
        }
    }

The function returns a float to a function that plays a movement depending on the movement for which minimax returns the highest value. The oldBoard and flippedBoard variables are dynamic matrices, and each recursion has a player (can be white or black depending on who is the turn) who plays a move on flippedBoard, the oldBoard variable is used to copy the previous board to the next board without losing information for every possible move.

If this explanation is not clear, please let me know, I will try my best to explain.
Note: I currently have the search function at a depth of 5.

How do I write a float function that accepts float n and returns the floor of n without using java.lang.Math?

I tried to convert n to an int, and somehow it worked.

static int floor(float n){  
    return (int) n;
}

It's okay?

php – Call a function from do_action

I am a little confused. I need to connect to the Events plugin so that when a user confirms their attendance, they execute a function to add the user to our client's MailChimp account.

The plugin documents give this

do_action( 'event_tickets_rsvp_attendee_created', int $attendee_id, int $post_id, string $order_id, int $product_id )

which can be found here: https://docs.theeventscalendar.com/reference/hooks/event_tickets_rsvp_attendee_created/

I have written something simple to test:

function my_custom_function () {
?>

<? php
}
add_action (& # 39; event_tickets_rsvp_attendee_created & # 39 ;, & # 39; my_custom_function & # 39 ;, 999);

Unfortunately I can't get any results. Can anyone point out what I am doing wrong or, better yet, what I need to do to achieve my goal?

Thank you

javascript: why is my function running out when running with a larger dataset?

I'm working on a Code Kata

// There is a queue for the self-checkout tills at the supermarket. 
// Your task is write a function to calculate the total time 
// required for all the customers to check out!
// input
// customers: an array of positive integers representing the queue. 
//    Each integer represents a customer, and its value is the amount 
//    of time they require to check out.
// n: a positive integer, the number of checkout tills.

A common solution is

function queueTime(customers, n) {
  // create a new array to represent each till
  // start each till at 0 minutes
  const tills = new Array(n).fill(0);
  // loop through the customers
  for (let i = 0; i < customers.length; i++) {
    // find till with least minutes 
    const shortestTill = Math.min(...tills)
    // find index of shortest till
    const index = arr.indexOf(shortestTill)
    // increase shortest till mins with current customer
    arr(index) += customers(i);
  }
  // return the longest till 
  return Math.max(...tills);
}

My first solution, albeit a longer one, seems to work, however timeout is running when I run it on a node with big data set. I'm sure there is probably some infinite loop or time complexity issue that I'm creating but can't identify.

Where in my code should I refactor to fix this problem?

function queueTime(customers, n) {
  // checking edge case
  if (customers.length === 0) return 0
  // initial time
  let time = 0
  // create a lookup to see if each till is open, where each
  //key is the till number and the val is the time needed for each to finish
  memo = {}
  for (let i = 1; i <= n; i++) {
    memo(i) = customers.shift()
  }
  // not necessarily needed because I'm using returns in the while loop,
  // but the intention is to break the loop
  let completed = false
  // solving the problem was taking two different approaches so
  // this variable allows me to check which approach to use
  let moreTillsThanCustomers = false
  // len = memo.length
  let len = Object.keys(memo).length
  for (let i = 1; i <= len; i++) {
    // if any didn't have a customer to fill the spot, then moreTillsThanCustomers = true
    if (memo(i) === undefined) {
      moreTillsThanCustomers = true
    }
  }
  if (!moreTillsThanCustomers) {
    while (!completed) {
      let found = false
      // if there are any open spots and customers left, we 'found' a spot to fill and can break out of the loop
      for (let i = 1; i <= len; i++) {
        if (memo(i) === 'open') {
          if (customers.length) {
            memo(i) = customers.shift()
              found = true
              break
          }
        }
      }
      // if no spot was found, increase the time by one  and reduce all
      // till times by 1 or to 'open
      if (!found) {
        time++
        for (let i = 1; i <= len; i++) {
          if (memo(i) === 1) {
            memo(i) = 'open'
          } else {
            memo(i)--
          }
        }
      }
      // if every value is 'open' and there are no customers left, we're done
      if (Object.values(memo).every(value => value === 'open')&& !customers.length) {
        completed = true
        return time
      }
    }
    // if there are more tills than customers
  } else {
    while (!completed) {
      // if a  memo is at 0, it's done, otherwise reduce it by one
      for (let i = 1; i <= len; i++) {
        if (memo(i) === 0) {
          memo(i) = undefined
        } else if (memo(i) !== undefined) {
          memo(i)--
        }
      }
      // if all are done, we're done
      if (Object.values(memo).every(value => value === undefined)) {
        completed = true
        return time
      }
      //increase time
      time++
    }
  }
  return time
}

Wait times on the node

console.log(
  queueTime((28, 9, 27, 37, 12, 33, 20, 31, 19, 18, 3, 8, 39, 40, 49), 5)
)

How to exploit this C program to call a certain function?

The goal is to call the function foo in the following program:

struct object {
    unsigned char buf(36);
    void (*fp)();
};

void baz(struct object * obj, unsigned int num) {
    for (int i = 0; i < num; i++) {
        unsigned int x;
        scanf("%d", &x);
        if (x == 0) break;
        obj->buf(i) = x & 0x000000ff;
    }
}

void foo() { // target
}

void bar() {
}

int main() {
    setvbuf(stdin,  NULL, _IONBF, 0); 
    setvbuf(stdout, NULL, _IONBF, 0); 
    setvbuf(stderr, NULL, _IONBF, 0);

    struct object * obj = malloc(sizeof(struct object));
    memset(obj->buf, 0, 36);
    obj->fp = &bar;

    int num;
    scanf("%d", &num);
    if (num > 36) {
        num = 0;
    } else {
        baz(obj, num);
    }

    for (int i = 0; i < num; i++) {
        printf("%d. t", i + 1);
        for (int j = 0; j < obj->buf(i); j++) {
            printf("*");
        }
        puts("");
    }

    obj->fp();
    free(obj);
}

My thoughts were to modify fp in obj (which is called at the end) so it points to foo instead of bar. By entering a negative number for num such that it becomes a large positive number when launched at unsigned int in baz, this should allow modification of fp overflowing buf in obj. However, this would require the direction of foo which changes every time the program is run.

I would appreciate any ideas or suggestions to solve this problem.

functional programming: user-defined function to parse multiple csvs, create variables, and count NA in R

I have about 100 data sets with different variables (and different numbers of variables) but each data set has a household ID (hh_ID) as identifier. Variables represent survey questions. Each csv represents a different type of survey. I want to write a custom function that counts the number of times a household was asked a question and the number of times a question was skipped (NA). The problem I have is changing the name of the variables and counting through csvs.

Let's say two dataframes look like this:

hh_ID <- c(1,1,2,2,2)
question1 <- c(NA,1,0,0,0)
question2 <- c(1,1,NA,0,0)
df1 <- data.frame(hh_ID, question1, question2)

hh_ID <- c(1,1,1,2,2)
question3 <- c(NA,NA,0,0,0)
question4 <- c(1,1,1,NA,NA)
df2 <- data.frame(hh_ID, question3, question4)

I need the final dataframe to make it look like this:

question1_count <- c(2,3)
question1_NAs   <- c(1,0)
question2_count <- c(2,3)
question2_NAs   <- c(0,1)
question3_count <- c(3,2)
question3_NAs   <- c(2,0)
question4_count <- c(3,2)
question4_NAs <- c(0,2)
finaldf <- data.frame(hh_ID,question1_count, question1_NAs,question2_count,question2_NAs,question3_count,question3_NAs, question4_count,question4_NAs) 

This is what I have so far:

# read in each dta file
filenames <- list.files(path=mydirectory, pattern=".*dta")
for (i in 1:length(filenames)){
assign(filenames(i), read_dta(paste("", filenames(i), sep=''))
)}

variable_NA_count <- function(dataset, col_name){
temp <- dataset %>% group_by(hh_ID) %>% summarise(question_count = n()) 
temp1 <- aggregate(col_name ~ hh_ID, data=dataset, function(x) {sum(is.na(x))}, na.action = NULL)
final <- merge(temp, temp1, by = "hh_ID")
return(final)}

frequency <- function(dataset, col_name){
temp <- variable_NA_count(dataset, col_name)
temp <- temp %>% select(question1_count = question_count,
                        question1_NAs = col_name)}

The problem is that I want each variable name to end in "_count" and "_NAs" without explicitly typing "question1_count = question_count". I have hundreds of variables in csvs, so I need a function that reads every csv, reads each column name, count the number of times a household was asked a question and the number of times they did not respond. I have tried various ways such as paste function but still hitting a wall.

Thank you!

complexity theory: why is this function computable in polynomial time?

Given alphabet $ {0,1 } $I read that the following function $ f $ is computable in polynomial time relative to the input $ w $

$$
f (w) = w10 ^ {| w | ^ 2- | w | -1}
$$

that is to say $ f $ It can be a $ TM $ receiving $ w $ and exits $ w10 ^ {| w | ^ 2- | w | -1} $. But why is it computable in polynomial time when it has a component? $ 0 ^ g (w) $ for $ g (w) = | w | ^ 2- | w | -1 $? That is, the size of the input is in the exponent part.

c # – I can't find fault in my jump function

I don't know why, but my jump method doesn't work. My character can only jump on a single object. The other obstacle has no influence on the player. I really don't see my mistake

     foreach (RectangleShape obstacles in MoveAtObjectList)
               {
                   MainPlayer.Move(deltaTime, obstacles);
               }

               foreach (RectangleShape obstacles in JumpAtObjectList)
               {
                   MainPlayer.Jump(deltaTime, obstacles);
                   break;
               }

               Draw();

               Window.Display();
           }
       }
   }
}

This was part of my main class, where I call the jump method inside a foreach loop. Here in my Payer class I tried to write the jump function.

using SFML.Graphics;
using SFML.System;
using SFML.Window;

namespace Pong3final
{
    class Player : RectangleShape
    {

        float CollisionDistance = 0.5f;

        float PlayerSpeed = 50;
        float JumpSpeed = 100;
        float FallSpeed = 100;
        float JumpTimer;

        bool JumpBool = false;
        bool Fall = true;

public  void Jump(float deltaTime, RectangleShape collisionObject)
        {

            if (Keyboard.IsKeyPressed(Keyboard.Key.Space) && !Fall && CheckCollision(this, collisionObject))
            {
                JumpBool = true;
            }

            //Player is jumping
            if (JumpBool)
            {
                JumpTimer += deltaTime;

                this.Position -= new Vector2f(0, JumpSpeed) * deltaTime;

                if (JumpTimer > 0.5f)
                {
                    JumpBool = false;
                    Fall = true;
                    JumpTimer = 0;
                }
            }

            //Player is falling when he doesnt touch anything and he isnt jumping
            else if (!CheckCollision(this, collisionObject))
            {
                Fall = true;
            }

            //Player is falling
            if (!JumpBool && !CheckCollision(this, collisionObject) && Fall)
            {
                this.Position += new Vector2f(0, FallSpeed) * deltaTime;

                if (CheckCollision(this, collisionObject)) //Player stops falling because of a collision with an object
                {
                    Fall = false;
                }
            }
        }


        public void Move(float deltaTime, RectangleShape collisionObject)
        {
            {
                Vector2f MovePlayerPosition = Position;

                if ((Keyboard.IsKeyPressed(Keyboard.Key.Left) || Keyboard.IsKeyPressed(Keyboard.Key.A)))
                {

                    MovePlayerPosition -= new Vector2f(PlayerSpeed, 0) * deltaTime;

                    FloatRect collisionOverlap;

                    if (CheckCollision(this, collisionObject, out collisionOverlap))
                    {
                       MovePlayerPosition = MovePlayerPosition + new Vector2f(collisionOverlap.Width + CollisionDistance, 0);
                    }    
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.Right) || Keyboard.IsKeyPressed(Keyboard.Key.D))
                {

                    MovePlayerPosition += new Vector2f(PlayerSpeed, 0) * deltaTime;

                    FloatRect collisionOverlap;

                    if (CheckCollision(this, collisionObject, out collisionOverlap))
                    {
                       MovePlayerPosition = MovePlayerPosition - new Vector2f(collisionOverlap.Width + CollisionDistance, 0);
                    }                  
                }

                Position = MovePlayerPosition;
            }
        }


        public static bool CheckCollision(RectangleShape obj1, RectangleShape obj2, out FloatRect overlap)
        {
            FloatRect obj1Collider = obj1.GetGlobalBounds();
            FloatRect obj2Collider = obj2.GetGlobalBounds();

            //Nur die rechte, linke und obere Seite kollidiert
            if (obj1Collider.Intersects(obj2Collider, out overlap))
            {
                return true;
            }
            overlap = new FloatRect();
            return false;
        }

        public static bool CheckCollision(RectangleShape obj1, RectangleShape obj2)
        {
            FloatRect obj1Collider = obj1.GetGlobalBounds();
            FloatRect obj2Collider = obj2.GetGlobalBounds();

            return obj1Collider.Intersects(obj2Collider);
        }
    }
}

nt.number theory – Applications of the eta function of Atiyah-Patodi-Singer $ eta (s) $

Atiya, Patodi, and Singer used the eta function of a differential operator to derive their famous index theorem, and it is given by

$$
eta (s) = sum _ { lambda neq 0} ( mathrm {sign} lambda) | lambda | – s
$$

where the sum goes over the operator's non-zero eigenvalues. The limit $ lim_ {s a 0} eta (0) $ it is the variant eta that appears in the index theorem itself.

My question is: are there known applications for the eta function evaluated at other values ​​of $ s $ ?