diff --git a/docs/index.md b/docs/index.md index 760b94340a..c850f66a5a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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/). \ No newline at end of file diff --git a/docs/languages/beef/index.md b/docs/languages/beef/index.md index f531b8832c..453e5207cd 100644 --- a/docs/languages/beef/index.md +++ b/docs/languages/beef/index.md @@ -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 @@ -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) diff --git a/docs/languages/index.md b/docs/languages/index.md index d730d26674..d2dcdaaa2d 100644 --- a/docs/languages/index.md +++ b/docs/languages/index.md @@ -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 @@ -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) diff --git a/docs/projects/index.md b/docs/projects/index.md index a91804c579..c5bbe6d62b 100644 --- a/docs/projects/index.md +++ b/docs/projects/index.md @@ -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 --- diff --git a/docs/projects/maximum-subarray/beef/index.md b/docs/projects/maximum-subarray/beef/index.md new file mode 100644 index 0000000000..2c4b02a1aa --- /dev/null +++ b/docs/projects/maximum-subarray/beef/index.md @@ -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 ParseInt(StringView str) + where T : IParseable + { + 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 ParseIntList(StringView str, List arr) + where T: IParseable + { + arr.Clear(); + for (StringView item in str.Split(',')) + { + switch (ParseInt(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(List arr) + where T : operator explicit int, operator T + T, IMinMaxValue + where int : operator T <=> T + { + T bestSum = T.MinValue; + T currentSum = default(T); + for (T val in arr) + { + currentSum = val + Math.Max(default(T), currentSum); + bestSum = Math.Max(currentSum, bestSum); + } + + return bestSum; + } + + public static int Main(String[] args) + { + if (args.Count < 1) + { + Usage(); + } + + List arr = scope .(); + if (ParseIntList(args[0], arr) case .Err) + { + Usage(); + } + + int32 result = MaximumSubarray(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). \ No newline at end of file diff --git a/docs/projects/maximum-subarray/index.md b/docs/projects/maximum-subarray/index.md index 39a91cccb5..df4ce675c1 100644 --- a/docs/projects/maximum-subarray/index.md +++ b/docs/projects/maximum-subarray/index.md @@ -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 @@ -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)