Skip to content

Commit

Permalink
Generated Sample Programs website automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 15, 2024
1 parent d00a699 commit b79cde1
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
date: 2018-03-15
last-modified: 2024-02-11
last-modified: 2024-02-15
layout: default
title: Sample Programs in Every Language
---

Welcome to Sample Programs in Every Language, a collection of code snippets in as many languages as possible. Thanks for taking an interest in our collection which currently contains 1051 articles written by 230 authors.
Welcome to Sample Programs in Every Language, a collection of code snippets in as many languages as possible. Thanks for taking an interest in our collection which currently contains 1052 articles written by 230 authors.

If you'd like to contribute to this growing collection, check out our [contributing document](https://github.com/TheRenegadeCoder/sample-programs/blob/master/.github/CONTRIBUTING.md) for more information. In addition, you can explore our documentation which is organized by [project](/projects) and by [language](/languages). If you don't find what you're look for, check out our list of related [open-source projects](/related). Finally, if code isn't your thing but you'd still like to help, there are plenty of other ways to [support the project](https://therenegadecoder.com/updates/5-ways-you-can-support-the-renegade-coder/).
3 changes: 2 additions & 1 deletion docs/languages/beef/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
date: 2024-01-11
featured-image: programming-languages.jpg
last-modified: 2024-02-11
last-modified: 2024-02-15
layout: default
tags:
- beef
Expand Down Expand Up @@ -36,6 +36,7 @@ No 'Description' section available. [Please consider contributing](https://githu
- [Longest Palindromic Substring in Beef](https://sampleprograms.io/projects/longest-palindromic-substring/beef)
- [Longest Word in Beef](https://sampleprograms.io/projects/longest-word/beef)
- [Maximum Array Rotation in Beef](https://sampleprograms.io/projects/maximum-array-rotation/beef)
- [Maximum Subarray in Beef](https://sampleprograms.io/projects/maximum-subarray/beef)
- [Merge Sort in Beef](https://sampleprograms.io/projects/merge-sort/beef)
- [Palindromic Number in Beef](https://sampleprograms.io/projects/palindromic-number/beef)
- [Prime Number in Beef](https://sampleprograms.io/projects/prime-number/beef)
Expand Down
6 changes: 3 additions & 3 deletions docs/languages/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
date: 2018-03-15
featured-image: programming-languages.jpg
last-modified: 2024-02-11
last-modified: 2024-02-15
layout: default
title: Programming Languages
---

Welcome to the Languages page! Here, you'll find a list of all of the languages represented in the collection. At this time, there are 153 languages, of which 152 are tested, 1 is untestable, and 861 code snippets.
Welcome to the Languages page! Here, you'll find a list of all of the languages represented in the collection. At this time, there are 153 languages, of which 152 are tested, 1 is untestable, and 862 code snippets.

## Language Collections by Letter

Expand Down Expand Up @@ -56,7 +56,7 @@ The 'A' collection contains 4 languages, of which 4 are tested, and 41 code snip

### B

The 'B' collection contains 9 languages, of which 9 are tested, and 63 code snippets.
The 'B' collection contains 9 languages, of which 9 are tested, and 64 code snippets.

- [Baik](https://sampleprograms.io/languages/baik)
- [Ballerina](https://sampleprograms.io/languages/ballerina)
Expand Down
2 changes: 1 addition & 1 deletion docs/projects/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
date: 2018-03-15
featured-image: programming-projects-in-every-language.jpg
last-modified: 2024-02-11
last-modified: 2024-02-15
layout: default
title: Programming Projects in Every Language
---
Expand Down
125 changes: 125 additions & 0 deletions docs/projects/maximum-subarray/beef/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
authors:
- rzuckerm
date: 2024-02-15
featured-image: maximum-subarray-in-every-language.jpg
last-modified: 2024-02-15
layout: default
tags:
- beef
- maximum-subarray
title: Maximum Subarray in Beef
---

Welcome to the [Maximum Subarray](https://sampleprograms.io/projects/maximum-subarray) in [Beef](https://sampleprograms.io/languages/beef) page! Here, you'll find the source code for this program as well as a description of how the program works.

## Current Solution

{% raw %}

```beef
using System;
using System.Collections;

namespace MaximumSubarray;

class Program
{
public static void Usage()
{
Console.WriteLine(
"""
Usage: Please provide a list of integers in the format: "1, 2, 3, 4, 5"
"""
);
Environment.Exit(0);
}

public static Result<T> ParseInt<T>(StringView str)
where T : IParseable<T>
{
StringView trimmedStr = scope String(str);
trimmedStr.Trim();

// T.Parse ignores single quotes since they are treat as digit separators -- e.g. 1'000
if (trimmedStr.Contains('\''))
{
return .Err;
}

return T.Parse(trimmedStr);
}

public static Result<void> ParseIntList<T>(StringView str, List<T> arr)
where T: IParseable<T>
{
arr.Clear();
for (StringView item in str.Split(','))
{
switch (ParseInt<T>(item))
{
case .Ok(let val):
arr.Add(val);

case .Err:
return .Err;
}
}

return .Ok;
}

// Find maximum subarray using Kadane's algorithm.
// Source: https://en.wikipedia.org/wiki/Maximum_subarray_problem#No_empty_subarrays_admitted
public static T MaximumSubarray<T>(List<T> arr)
where T : operator explicit int, operator T + T, IMinMaxValue<T>
where int : operator T <=> T
{
T bestSum = T.MinValue;
T currentSum = default(T);
for (T val in arr)
{
currentSum = val + Math.Max<T>(default(T), currentSum);
bestSum = Math.Max<T>(currentSum, bestSum);
}

return bestSum;
}

public static int Main(String[] args)
{
if (args.Count < 1)
{
Usage();
}

List<int32> arr = scope .();
if (ParseIntList<int32>(args[0], arr) case .Err)
{
Usage();
}

int32 result = MaximumSubarray<int32>(arr);
Console.WriteLine(result);

return 0;
}
}

```

{% endraw %}

Maximum Subarray in [Beef](https://sampleprograms.io/languages/beef) was written by:

- rzuckerm

If you see anything you'd like to change or update, [please consider contributing](https://github.com/TheRenegadeCoder/sample-programs).

## How to Implement the Solution

No 'How to Implement the Solution' section available. [Please consider contributing](https://github.com/TheRenegadeCoder/sample-programs-website).

## How to Run the Solution

No 'How to Run the Solution' section available. [Please consider contributing](https://github.com/TheRenegadeCoder/sample-programs-website).
3 changes: 2 additions & 1 deletion docs/projects/maximum-subarray/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
date: 2020-10-14
featured-image: maximum-subarray-in-every-language.jpg
last-modified: 2023-10-14
last-modified: 2024-02-15
layout: default
tags:
- maximum-subarray
Expand Down Expand Up @@ -76,6 +76,7 @@ Usage: Please provide a list of integers in the format: "1, 2, 3, 4, 5"
## Articles

- [Maximum Subarray in Algol68](https://sampleprograms.io/projects/maximum-subarray/algol68)
- [Maximum Subarray in Beef](https://sampleprograms.io/projects/maximum-subarray/beef)
- [Maximum Subarray in Commodore Basic](https://sampleprograms.io/projects/maximum-subarray/commodore-basic)
- [Maximum Subarray in Euphoria](https://sampleprograms.io/projects/maximum-subarray/euphoria)
- [Maximum Subarray in Mathematica](https://sampleprograms.io/projects/maximum-subarray/mathematica)
Expand Down

0 comments on commit b79cde1

Please sign in to comment.