// Arup Guha
// 12/5/2023
// Code for 2023 COP 3502 Final Exam Part B Question 5 - Both Versions

#include <stdio.h>

#define DEBUG 1

int hitfloor(int h, int v, int a);
int earnmoney(int target, int d, int x);


// Teest.
int main() {
    printf("%d\n", hitfloor(100, 1, 9));
    printf("%d\n", earnmoney(1000, 20, 5));
    return 0;
}

// Returns the # of full seconds elapsed by which time the object has hit the floor.
int hitfloor(int h, int v, int a) {

    // For debugging.
    if (DEBUG) printf("call with %d %d %d\n", h, v, a);

    // No more seconds left.
    if (h <= 0) return 0;

    // In one second we go v feet down and add a to our acceleration.
    return 1 + hitfloor(h-v, v+a, a);
}

// Note: this function is exactly the same as the one above, but just written with
// variable names for the new flavor text.
int earnmoney(int target, int d, int x) {
    if (DEBUG) printf("call with %d %d %d\n", target, d, x);
    if (target <= 0) return 0;
    return 1 + earnmoney(target-d, d+x, x);
}
