[48in24 Exercise] [08-27] Pascal's Triangle

This issue is a discussion for contributors to collaborate in getting ready to be featured in 48in24. Please refer to this forum topic for more info.


We will be featuring Pascal’s Triangle from Aug 27 onwards.

Staff jobs

These are things for Erik/Jeremy to do:

  • ☐ Check/update exercise in Problem Specifications
  • ☐ Create + schedule video

Community jobs

For each track:

  • Implement Pascal’s Triangle
  • Add approaches (and an approaches introduction!) for each idiomatic or interesting/educational approach.
  • Add video walkthroughs (record yourself solving and digging deeper into the exercise).
  • Highlight up to 16 different featured exercises (coming soon)

Existing Approaches

You can use these as the basis for approaches on your own tracks. Feel free to copy/paste/reuse/rewrite/etc as you see fit! Maybe ask ChatGPT to translate to your programming language.

Track Statuses

You can see an overview of which tracks have implemented the exercise at the #48in24 implementation status page.

I’ve currently gathered the following solutions to feature:

  1. Go: for loops
    Use for loops to iterate over the rows and columns

  2. Standard ML: recursion
    Use recursion

  3. F#: scan on rows
    Use scan to incrementally build up the rows

  4. F#: scan on row
    Use scan to incrementally build up the row

  5. Kotlin: generate lazy sequence
    Generate a lazy sequence (like scan) and take the N rows

  6. AWK: for loop using previous row
    Use a for loop and use previous rows values

  7. Prolog: pairwise combine previous row with 0 prepended and appended
    Get the previous row, and map that with 0 prepended and appended

  8. Nim: use factorial to calculate the binomial
    Use the factorial to calculate the binomial

  9. Julia: binomial and comprehension
    Use the binomial function to generate the values and a comprehension to create the rows

If anyone has more suggestions, do let us know!

let me toot my own horn: I came up with an extremely minimal solution in awk: glennj's solution for Pascal's Triangle in AWK on Exercism

3 Likes

That is my favorite solution of them all @glennj!

@BethanyG, I noticed the Python track doesn’t use an apostrophe in the exercise name (see python/config.json at a47255b9bba08739a8752e5f1c88b2cc0f5f49c3 · exercism/python · GitHub). If this is in error, should I make a quick PR to fix that?

@BNAndras Thanks for the head’s up! :smile: I was in there this morning re-ordering the Track Docs (thanks @glennj for bringing up and getting that issue fixed!), so I went ahead and fixed it:

[Python Track Config] Changed `Pascals Triangle` to `Pascal's Triangle` for the Exercise name. by BethanyG · Pull Request #3744 · exercism/python · GitHub.

Let’s hope I didn’t bork anything. :wink:

1 Like

@ErikSchierboom – FYI, the Python track has forced a recursive implementation here (not that you need to feature a Python solution). Might or might not be worth a mention that different tracks have different implementations/requirements.

1 Like

A cursory Github search shows CoffeeScript, D, Gleam, J, jq, Powershell, SML, Vlang, and Wren have “Pascals Triangle” as well.

Edit - I submitted PRs for CoffeeScript and D, but if anybody wants to deal with the others, go ahead. Otherwise, I’ll get to it by the end of the week.

3 Likes

Fixed in jq.

PRs created in wren and gleam.

3 Likes

Additional PRs submitted for J, PowerShell, SML, and Vlang.

Here’s where the problem likely came from:

vlang bin/bootstrap_practice_exercise.sh has

NAME=$(echo $SLUG | sed -e 's/-/ /g' -e 's/\b\(.\)/\u\1/g' )
...
jq --arg slug "$SLUG" --arg name "$NAME" --arg uuid "$UUID" \

Others might be similar:

ballerina/bin/add-exercise:jq --arg slug "${slug}" --arg uuid "${uuid}" --arg name "${name}" \
fortran/bin/add-exercise:jq --arg slug "${slug}" --arg uuid "${uuid}" --arg name "${name}" \
jq/bin/add-exercise:    --arg name "${name}"                 \
unison/bin/add-exercise:jq --arg slug "${slug}" --arg uuid "${uuid}" --arg name "${name}" \
unison/bin/generate-test-annotation:    jq -n --arg name "${test_name}" --arg test_code "${test_code}" '{$test_code, $name}'
zig/bin/add-exercise:jq --arg slug "${slug}" --arg uuid "${uuid}" --arg name "${name}" \

For some of my own exercise contributions on other tracks that don’t have similar scripts, I adapted from the above.

We should instead be using something like

bin/configlet create --practice-exercise "${slug}" --author "${author}" --difficulty "${difficulty}"
1 Like

Indeed.

A PR to update the jq add-exercise script to call configlet create instead of a series of “manual” steps.

3 Likes

The exercise is currently unimplemented on the assembly tracks. Would it be reasonable to ask students to generate a flattened integer sequence?

size_t rows(unsigned* dest, unsigned count);

When count is 4, solutions can populate dest with the integer sequence

        1,
        1, 1,
        1, 2, 1,
        1, 3, 3, 1

and return 10 (the sequence length and the 4th triangular number).

I would not want to use a value like -1 as a row delimiter.

I’m not well versed in assembly, so I’m hoping others can weigh in.

1 Like

Adding a couple of scripts to call configlet create

x86-64 Assembly

MIPS

1 Like

MIPS Pascal’s Triangle

2 Likes