Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/marlonmontenegro/projectstockpicker


https://github.com/marlonmontenegro/projectstockpicker

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Stock Picker

The Stock Picker exercise challenges you to develop a Ruby method that analyzes a given array of stock prices to determine the optimal days to buy and sell stocks, maximizing potential profit. This exercise encourages you to work with arrays, loops, and conditional statements while solving a real-world problem.

## Exercise Description

The goal of this exercise is to implement a Ruby method named `stock_picker` that takes an array of stock prices as input. The method should analyze the array to determine the best days to buy and sell stocks, ensuring maximum profit. The output should include the indices of the buy and sell days, as well as the calculated profit.

## Features

- **Nested Loop:** The solution involves using nested loops to compare all possible combinations of buy and sell days.
- **Profit Calculation:** The method calculates the potential profit by subtracting the buy price from the sell price.
- **Optimal Strategy:** The algorithm identifies the optimal combination of buy and sell days that results in the highest profit.
- **Output Presentation:** The method provides clear output by displaying the best buy and sell days as well as the calculated profit.

## Example

For instance, given the array `stocks = [17, 3, 6, 9, 15, 8, 6, 1, 10]`, the expected output might be:
Best days to buy and sell: [1, 4]

In this example, the method correctly identified the optimal buy and sell days and calculated the potential profit.