Skip to content

Commit

Permalink
Merge branch 'exercism:main' into sync-with-problem-specs
Browse files Browse the repository at this point in the history
  • Loading branch information
simisc authored Oct 28, 2024
2 parents 3027e9a + 8e5f887 commit 63d29a0
Show file tree
Hide file tree
Showing 59 changed files with 924 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
interval: 'monthly'
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
runs-on: ubuntu-22.04

- os: macos
runs-on: macos-12
runs-on: macos-13

name: ${{ matrix.os }}
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- name: Set path to gfortran
if: matrix.os == 'macos'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938

- name: Check if all exercise cmake files are up to date
run: ./bin/check-cmake-files-up-to-date
23 changes: 23 additions & 0 deletions .github/workflows/no-important-files-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: No important files changed

on:
pull_request_target:
types: [opened]
branches: [main]
paths:
- "exercises/concept/**"
- "exercises/practice/**"
- "!exercises/*/*/.approaches/**"
- "!exercises/*/*/.articles/**"
- "!exercises/*/*/.docs/**"
- "!exercises/*/*/.meta/**"

permissions:
pull-requests: write

jobs:
check:
uses: exercism/github-actions/.github/workflows/check-no-important-files-changed.yml@main
with:
repository: ${{ github.event.pull_request.head.repo.owner.login }}/${{ github.event.pull_request.head.repo.name }}
ref: ${{ github.head_ref }}
16 changes: 16 additions & 0 deletions .github/workflows/ping-cross-track-maintainers-team.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Ping cross-track maintainers team

on:
pull_request_target:
types:
- opened

permissions:
pull-requests: write

jobs:
ping:
if: github.repository_owner == 'exercism' # Stops this job from running on forks
uses: exercism/github-actions/.github/workflows/ping-cross-track-maintainers-team.yml@main
secrets:
github_membership_token: ${{ secrets.COMMUNITY_CONTRIBUTIONS_WORKFLOW_TOKEN }}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") # Intel fortran
set (CMAKE_Fortran_FLAGS "-warn all")
endif()
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFrotran
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFortran
set (CMAKE_Fortran_FLAGS "-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace")
endif()

Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ This policy was initially adopted from the Front-end London Slack community and
A version history can be seen on [GitHub](https://github.com/exercism/website-copy/edit/main/pages/code_of_conduct.md).

_This policy is a "living" document, and subject to refinement and expansion in the future.
This policy applies to the Exercism website, the Exercism GitHub organization, any other Exercism-related communication channels (e.g. Slack, Twitter, email) and any other Exercism entity or event._
This policy applies to the Exercism website, the Exercism GitHub organization, any other Exercism-related communication channels (e.g. Discord, Forum, Twitter, email) and any other Exercism entity or event._
23 changes: 12 additions & 11 deletions bin/fetch-configlet
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ get_download_url() {
local latest='https://api.github.com/repos/exercism/configlet/releases/latest'
local arch
case "$(uname -m)" in
x86_64) arch='x86-64' ;;
*686*) arch='i386' ;;
*386*) arch='i386' ;;
*) arch='x86-64' ;;
aarch64|arm64) arch='arm64' ;;
x86_64) arch='x86-64' ;;
*686*) arch='i386' ;;
*386*) arch='i386' ;;
*) arch='x86-64' ;;
esac
local suffix="${os}_${arch}.${ext}"
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${latest}" |
Expand All @@ -47,7 +48,7 @@ main() {
fi

local os
case "$(uname)" in
case "$(uname -s)" in
Darwin*) os='macos' ;;
Linux*) os='linux' ;;
Windows*) os='windows' ;;
Expand All @@ -58,8 +59,8 @@ main() {

local ext
case "${os}" in
windows*) ext='zip' ;;
*) ext='tar.gz' ;;
windows) ext='zip' ;;
*) ext='tar.gz' ;;
esac

echo "Fetching configlet..." >&2
Expand All @@ -69,16 +70,16 @@ main() {
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"

case "${ext}" in
*zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
esac

rm -f "${output_path}"

local executable_ext
case "${os}" in
windows*) executable_ext='.exe' ;;
*) executable_ext='' ;;
windows) executable_ext='.exe' ;;
*) executable_ext='' ;;
esac

local configlet_path="${output_dir}/configlet${executable_ext}"
Expand Down
20 changes: 20 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,26 @@
"practices": [],
"prerequisites": [],
"difficulty": 8
},
{
"slug": "protein-translation",
"name": "Protein Translation",
"uuid": "3d2ba0a1-2a2a-4e1f-89e8-c5add9ddceef",
"practices": [],
"prerequisites": [],
"difficulty": 5,
"topics": [
"lists",
"strings"
]
},
{
"slug": "binary-search",
"name": "Binary Search",
"uuid": "e8ecfec1-2fc2-4216-a468-ef8d63e69bee",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ string(REPLACE "-" "_" file ${exercise})
# Activate Fortran compiler warnings
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") # Intel fortran
if(WIN32)
set (CCMAKE_Fortran_FLAG ${CCMAKE_Fortran_FLAGS} "/warn:all")
add_compile_options(/warn:all)
else()
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-warn all")
add_compile_options(-warn all)
endif()
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFrotran
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace")
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFortran
add_compile_options(-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace)
endif()

# Configure to run all the tests?
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/acronym/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ string(REPLACE "-" "_" file ${exercise})
# Activate Fortran compiler warnings
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") # Intel fortran
if(WIN32)
set (CCMAKE_Fortran_FLAG ${CCMAKE_Fortran_FLAGS} "/warn:all")
add_compile_options(/warn:all)
else()
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-warn all")
add_compile_options(-warn all)
endif()
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFrotran
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace")
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFortran
add_compile_options(-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace)
endif()

# Configure to run all the tests?
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/allergies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ string(REPLACE "-" "_" file ${exercise})
# Activate Fortran compiler warnings
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") # Intel fortran
if(WIN32)
set (CCMAKE_Fortran_FLAG ${CCMAKE_Fortran_FLAGS} "/warn:all")
add_compile_options(/warn:all)
else()
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-warn all")
add_compile_options(-warn all)
endif()
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFrotran
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace")
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFortran
add_compile_options(-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace)
endif()

# Configure to run all the tests?
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/armstrong-numbers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ string(REPLACE "-" "_" file ${exercise})
# Activate Fortran compiler warnings
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") # Intel fortran
if(WIN32)
set (CCMAKE_Fortran_FLAG ${CCMAKE_Fortran_FLAGS} "/warn:all")
add_compile_options(/warn:all)
else()
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-warn all")
add_compile_options(-warn all)
endif()
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFrotran
set (CMAKE_Fortran_FLAGS ${CCMAKE_Fortran_FLAGS} "-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace")
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # GFortran
add_compile_options(-std=f2008 -W -Wall -Wextra -pedantic -fbacktrace)
endif()

# Configure to run all the tests?
Expand Down
29 changes: 29 additions & 0 deletions exercises/practice/binary-search/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Instructions

Your task is to implement a binary search algorithm.

A binary search algorithm finds an item in a list by repeatedly splitting it in half, only keeping the half which contains the item we're looking for.
It allows us to quickly narrow down the possible locations of our item until we find it, or until we've eliminated all possible locations.

~~~~exercism/caution
Binary search only works when a list has been sorted.
~~~~

The algorithm looks like this:

- Find the middle element of a _sorted_ list and compare it with the item we're looking for.
- If the middle element is our item, then we're done!
- If the middle element is greater than our item, we can eliminate that element and all the elements **after** it.
- If the middle element is less than our item, we can eliminate that element and all the elements **before** it.
- If every element of the list has been eliminated then the item is not in the list.
- Otherwise, repeat the process on the part of the list that has not been eliminated.

Here's an example:

Let's say we're looking for the number 23 in the following sorted list: `[4, 8, 12, 16, 23, 28, 32]`.

- We start by comparing 23 with the middle element, 16.
- Since 23 is greater than 16, we can eliminate the left half of the list, leaving us with `[23, 28, 32]`.
- We then compare 23 with the new middle element, 28.
- Since 23 is less than 28, we can eliminate the right half of the list: `[23]`.
- We've found our item.
13 changes: 13 additions & 0 deletions exercises/practice/binary-search/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Introduction

You have stumbled upon a group of mathematicians who are also singer-songwriters.
They have written a song for each of their favorite numbers, and, as you can imagine, they have a lot of favorite numbers (like [0][zero] or [73][seventy-three] or [6174][kaprekars-constant]).

You are curious to hear the song for your favorite number, but with so many songs to wade through, finding the right song could take a while.
Fortunately, they have organized their songs in a playlist sorted by the title — which is simply the number that the song is about.

You realize that you can use a binary search algorithm to quickly find a song given the title.

[zero]: https://en.wikipedia.org/wiki/0
[seventy-three]: https://en.wikipedia.org/wiki/73_(number)
[kaprekars-constant]: https://en.wikipedia.org/wiki/6174_(number)
19 changes: 19 additions & 0 deletions exercises/practice/binary-search/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"SimaDovakin"
],
"files": {
"solution": [
"binary_search.f90"
],
"test": [
"binary_search_test.f90"
],
"example": [
".meta/example.f90"
]
},
"blurb": "Implement a binary search algorithm.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Binary_search_algorithm"
}
32 changes: 32 additions & 0 deletions exercises/practice/binary-search/.meta/example.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module binary_search
implicit none
contains

function find(array, val) result(idx)
integer, dimension(:), intent(in) :: array
integer, intent(in) :: val
integer :: idx
integer :: start_index, end_index, middle_index

start_index = 1
end_index = size(array)

do while (end_index >= start_index)
middle_index = (end_index + start_index) / 2

if (array(middle_index) == val) then
idx = middle_index
return
end if

if (array(middle_index) > val) then
end_index = middle_index - 1
else if (array(middle_index) < val) then
start_index = middle_index + 1
end if
end do

idx = -1
end function

end module
43 changes: 43 additions & 0 deletions exercises/practice/binary-search/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[b55c24a9-a98d-4379-a08c-2adcf8ebeee8]
description = "finds a value in an array with one element"

[73469346-b0a0-4011-89bf-989e443d503d]
description = "finds a value in the middle of an array"

[327bc482-ab85-424e-a724-fb4658e66ddb]
description = "finds a value at the beginning of an array"

[f9f94b16-fe5e-472c-85ea-c513804c7d59]
description = "finds a value at the end of an array"

[f0068905-26e3-4342-856d-ad153cadb338]
description = "finds a value in an array of odd length"

[fc316b12-c8b3-4f5e-9e89-532b3389de8c]
description = "finds a value in an array of even length"

[da7db20a-354f-49f7-a6a1-650a54998aa6]
description = "identifies that a value is not included in the array"

[95d869ff-3daf-4c79-b622-6e805c675f97]
description = "a value smaller than the array's smallest value is not found"

[8b24ef45-6e51-4a94-9eac-c2bf38fdb0ba]
description = "a value larger than the array's largest value is not found"

[f439a0fa-cf42-4262-8ad1-64bf41ce566a]
description = "nothing is found in an empty array"

[2c353967-b56d-40b8-acff-ce43115eed64]
description = "nothing is found when the left and right bounds cross"
Loading

0 comments on commit 63d29a0

Please sign in to comment.