-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Comment, not an "issue". Thanks for putting your project on GitHub. I have written a Python script https://github.com/Beliavsky/Groq-Fortran-agent that uses LLMs on Groq cloud to solve problems in Fortran. The script feeds compiler error messages back to the LLM. Your LLM had trouble with "Best Time to Buy and Sell Stock", but for the prompt below
Write a Fortran program to solve this problem:
You are given an array prices where prices[i] is the price of a given stock on the ith day.
You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction, for both examples
below. If you cannot achieve any profit, return 0.
Example 1:
Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
Example 2:
Input: prices = [7,6,4,3,1] Output: 0 Explanation: In this case, no transactions are done and the max profit = 0.
Constraints:
1 <= prices.length <= 105
0 <= prices[i] <= 104
sample output from my script is
prompt:
Write a Fortran program to solve this problem:
You are given an array prices where prices[i] is the price of a given stock on the ith day.
You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction, for both examples
below. If you cannot achieve any profit, return 0.
Example 1:
Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
Example 2:
Input: prices = [7,6,4,3,1] Output: 0 Explanation: In this case, no transactions are done and the max profit = 0.
Constraints:
1 <= prices.length <= 105
0 <= prices[i] <= 104
Only output Fortran code. Do not give commentary.
model: qwen-2.5-coder-32b
Code compiled successfully after 1 attempt (generation time: 1.155 seconds, LOC=33)!
Running executable: .\main.exe
Output:
Maximum Profit Example 1: 5
Maximum Profit Example 2: 0
Total generation time: 1.155 seconds across 1 attempt
Compilation command: gfortran -Wfatal-errors -o main main.f90
with Fortran code
program max_profit_stock
implicit none
integer, dimension(:), allocatable :: prices
integer :: n, i, min_price, max_profit
! Example 1
prices = [7, 1, 5, 3, 6, 4]
n = size(prices)
min_price = prices(1)
max_profit = 0
do i = 2, n
if (prices(i) - min_price > max_profit) then
max_profit = prices(i) - min_price
end if
if (prices(i) < min_price) then
min_price = prices(i)
end if
end do
print *, 'Maximum Profit Example 1:', max_profit
! Example 2
prices = [7, 6, 4, 3, 1]
n = size(prices)
min_price = prices(1)
max_profit = 0
do i = 2, n
if (prices(i) - min_price > max_profit) then
max_profit = prices(i) - min_price
end if
if (prices(i) < min_price) then
min_price = prices(i)
end if
end do
print *, 'Maximum Profit Example 2:', max_profit
end program max_profit_stock
Metadata
Metadata
Assignees
Labels
No labels