Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonocarroll/triangles
Calculate Pythagorean Triples
https://github.com/jonocarroll/triangles
Last synced: 8 days ago
JSON representation
Calculate Pythagorean Triples
- Host: GitHub
- URL: https://github.com/jonocarroll/triangles
- Owner: jonocarroll
- License: gpl-3.0
- Created: 2023-08-06T00:28:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-11T13:39:36.000Z (over 1 year ago)
- Last Synced: 2024-11-15T14:42:59.977Z (2 months ago)
- Language: C
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
README
---
output: github_document
editor_options:
chunk_output_type: console
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# triangles
Wrap C code to calculate Pythagorean triples.
## Installation
You can install the development version of triangles with
``` r
# install.packages("remotes")
remotes::install_github("jonocarroll/triangles")
```## Example
This package is purely for demonstration purposes, supporting this blog post: https://jcarroll.com.au/2023/08/11/wrapping-c-code-in-an-r-package/
The wrapped C code involves many features I learned about so I built this package
to support the blog post in an effort to capture as many as possible. The processes
here are not new at all, but I found many of the existing resources to be either
out of date or confusing.The function `triangles()` takes a maximum hypotenuse length `maxval` and produces
a `data.frame()` in R. The columns represent the lengths of the sides of a
right triangle `a`, `b`, and `c` such that all of these are integers, along with the
sum of these (the perimeter of the triangle)```{r}
library(triangles)triangles(20)
```This is a complete `data.frame` returned from C
```{r}
x <- triangles(20)
str(x)
x[x$sum > 20 & x$sum < 35, ]
```Various iterations of the C code can be found in [inst/src](inst/src).