# Fortran playground

**URL:** <https://fortran-lang.discourse.group/t/fortran-playground/6290>\
**Category:** Help\
**Created:** [August 8, 2023, 4:43am UTC](https://fortran-lang.discourse.group/t/fortran-playground/6290 "2023-08-08T04:43:29Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [August 11, 2023, 3:01pm UTC](https://fortran-lang.discourse.group/t/fortran-playground/6290/20 "2023-08-11T15:01:51Z")

</div>

### Live Fortran pages (Online Compilers)

- [GodBolt compiler explorer](https://godbolt.org/)
- [fortran-lang "play"](https://play.fortran-lang.org/)
- [Lfortran](https://dev.lfortran.org)
- [CodersEditor.com](https://coderseditor.com/)
- [ideone.com](https://ideone.com/)
- [JDoodle (compiler options)](https://www.jdoodle.com/execute-fortran-online/)
- [myCompiler.io](https://www.mycompiler.io/new/fortran)
- [onecompiler.com](https://onecompiler.com/fortran)
- [OnlineGDB](https://www.onlinegdb.com/online_fortran_compiler)
- [rextester.com](https://rextester.com/l/fortran_online_compiler)
- [techiedelight.com](https://techiedelight.com/compiler/fortran)
- [TutorialsPoint (beautify)](https://www.tutorialspoint.com/compile_fortran_online.php)
- [W3Schools](https://www.w3schools.com/tryit/trycompiler.asp?filename=demo_fortran)

Just regarding an on-line playground and possible additional functionality, as has come up in bits in pieces in other discussions having one that can be customized allows not just for multiple compilers such as gfortran and lfortran to be supported, but to allow support of the fpm repository, for fortran snippets in this forum to be automatically runnable, as well as example programs in the documentation such as in the intrinsic descriptions, even some graphics capabilities, … I picture someone making a post of executable code, clicking on it and automatically having the code in an editor in a live fortran environment; running and modifiying it and reposting it; even having a version editable by the group and that the community can add examples to ala Rosetta Code like

## Sites for gathering programming idioms and programming chrestomathy

- [Rosetta Code (multi-lingual code samples)](https://www.rosettacode.org)
- [Fortran-specific Rosetta Code](http://rosettacode.org/wiki/Category:Fortran)
- [Exercism](https://exercism.io/)
- [Programming-idioms](https://www.programming-idioms.org/)
- [codingame](https://www.codingame.com/start)

Perhaps if a wish-list is gathered here or as an extension of the original playground project it could act as a seed project for testing the funding method(s) such as mentioned above; pending review of the resulting proposals? Direct funding, donation of time and technical skills, creation of useful documentation and examples, and incorporation of the results into development processes are all in some form of progress but do not yet feel easily accessible or easy to contribute to in all cases.

### Wish: playground integration with fpm packages

A live Fortran site with access to fpm repository packages (and maybe git repositories as well) touched upon at [0.8.2 fpm registry release](https://fortran-lang.discourse.group/t/fpm-version-0-8-2-released-centralized-registry-playground/5792)

### Wish: Integration of the playground with Discourse postings and fortran-lang documentation

So one wish is that a self-contained fortran post on this forum could automatically load on  
the live Fortran pages. On the playground that is simple up to the point of the size allowed  
in theory.

A manual example using a [code snippet](https://fortran-lang.discourse.group/t/fortran-code-snippets/2150) example:

- Recursive example [run in playground](https://play.fortran-lang.org/?code=%21%20jkd2022%0A%21%20How%20many%20ways%20can%20you%20change%20N%20dollars%20into%20coins%20%28cents%2C%20dimes%2C%20nickels%2C%20quarters%2C%2050%20cent%20and%20dollar%20coins%29%3F%0A%21%20Here%E2%80%99s%20a%20nice%20compact%20solution%20using%20Fortran%E2%80%99s%20recursion%20feature.%0A%0Aprogram%20change_for_dollars%0Aimplicit%20none%0Ainteger%20ndollars%2Cncents%0A%0Awrite%28%2A%2C%27%28%22Enter%20number%20of%20dollars%20%3A%20%22%29%27%2Cadvance%3D%27NO%27%29%0Aread%28%2A%2C%2A%29%20ndollars%0A%21%20convert%20to%20cents%0Ancents%3Dndollars%2A100%0A%0Awrite%28%2A%2C%27%28%22Number%20of%20ways%20%22%2CI4%2C%22%20dollars%20can%20be%20changed%20to%20coins%20is%22%29%27%29%20ndollars%0Awrite%28%2A%2C%27%28I8%29%27%29%20nways%28ncents%2C6%29%0A%0Acontains%0A%0Arecursive%20function%20nways%28ncents%2Cncoins%29%20result%28nw%29%0Aimplicit%20none%0A%21%20arguments%0Ainteger%2C%20intent%28in%29%20%3A%3A%20ncents%2Cncoins%0Ainteger%20nw%0A%21%20local%20variables%0Ainteger%20c%2Ci%0A%21%20cent%2C%20nickel%2C%20dime%2C%20quarter%2C%2050%20cent%20and%20dollar%20coin%0Ainteger%2C%20parameter%20%3A%3A%20coin%286%29%3D%5B1%2C5%2C10%2C25%2C50%2C100%5D%0Aif%20%28ncoins.eq.0%29%20then%0A%20%20nw%3D0%0A%20%20return%0Aend%20if%0Anw%3Dnways%28ncents%2Cncoins-1%29%0Ac%3Dcoin%28ncoins%29%0Aif%20%28ncents.lt.c%29%20return%0Ado%20i%3D1%2Cncents%2Fc%0A%20%20nw%3Dnw%2Bnways%28ncents-i%2Ac%2Cncoins-1%29%0Aend%20do%0Aif%20%28mod%28ncents%2Cc%29.eq.0%29%20nw%3Dnw%2B1%0Aend%20function%0A%0Aend%20program%0A)

> **recursive example code**
>
> ```fortran
> ! jkd2022
> ! How many ways can you change N dollars into coins (cents, dimes, nickels, quarters, 50 cent and dollar coins)?
> ! Here’s a nice compact solution using Fortran’s recursion feature.
> 
> program change_for_dollars
> implicit none
> integer ndollars,ncents
> 
> write(*,'("Enter number of dollars : ")',advance='NO')
> read(*,*) ndollars
> ! convert to cents
> ncents=ndollars*100
> 
> write(*,'("Number of ways ",I4," dollars can be changed to coins is")') ndollars
> write(*,'(I8)') nways(ncents,6)
> 
> contains
> 
> recursive function nways(ncents,ncoins) result(nw)
> implicit none
> ! arguments
> integer, intent(in) :: ncents,ncoins
> integer nw
> ! local variables
> integer c,i
> ! cent, nickel, dime, quarter, 50 cent and dollar coin
> integer, parameter :: coin(6)=[1,5,10,25,50,100]
> if (ncoins.eq.0) then
> nw=0
> return
> end if
> nw=nways(ncents,ncoins-1)
> c=coin(ncoins)
> if (ncents.lt.c) return
> do i=1,ncents/c
> nw=nw+nways(ncents-i*c,ncoins-1)
> end do
> if (mod(ncents,c).eq.0) nw=nw+1
> end function
> 
> end program
> 
> ```

---

_[View the full topic](https://fortran-lang.discourse.group/t/fortran-playground/6290)._
