[48in24 Exercise] [01-16] Leap

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


We will be featuring Leap from Jan 16th onwards.

Staff jobs

These are things for Erik/Jeremy to do:

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

Community jobs

For each track:

  • Implement Leap
  • 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

Implemented Approaches introduction Num approaches Num video walkthroughs
8th :white_check_mark: :x: - -
ABAP :white_check_mark: :x: - -
AWK :white_check_mark: :x: - -
Ballerina :white_check_mark: :x: - -
Bash :white_check_mark: :x: - -
C :white_check_mark: :x: - -
C# :white_check_mark: :white_check_mark: 5 1
C++ :white_check_mark: :x: - -
CFML :white_check_mark: :x: - -
Clojure :white_check_mark: :x: - -
COBOL :white_check_mark: :x: - -
CoffeeScript :white_check_mark: :x: - -
Common Lisp :x: :x: - -
Crystal :white_check_mark: :x: - -
D :white_check_mark: :x: - -
Dart :white_check_mark: :x: - -
Delphi Pascal :white_check_mark: :x: - -
Elixir :white_check_mark: :x: - -
Elm :white_check_mark: :x: - -
Emacs Lisp :white_check_mark: :x: - -
Erlang :white_check_mark: :x: - -
F# :white_check_mark: :x: - -
Fortran :white_check_mark: :x: - -
Gleam :white_check_mark: :x: - -
Go :white_check_mark: :white_check_mark: 4 -
Groovy :white_check_mark: :x: - -
Haskell :white_check_mark: :white_check_mark: 3 -
Java :white_check_mark: :white_check_mark: 4 -
JavaScript :white_check_mark: :white_check_mark: 4 -
jq :white_check_mark: :x: - -
Julia :white_check_mark: :white_check_mark: - -
Kotlin :white_check_mark: :white_check_mark: 4 -
LFE :white_check_mark: :x: - -
Lua :white_check_mark: :x: - -
MIPS Assembly :white_check_mark: :x: - -
Nim :white_check_mark: :x: - -
Objective-C :white_check_mark: :x: - -
OCaml :white_check_mark: :x: - -
Perl :white_check_mark: :x: - -
Pharo :white_check_mark: :x: - -
PHP :white_check_mark: :x: - -
PL/SQL :white_check_mark: :x: - -
PowerShell :white_check_mark: :x: - -
Prolog :white_check_mark: :x: - -
PureScript :white_check_mark: :x: - -
Python :white_check_mark: :white_check_mark: 3 -
R :white_check_mark: :x: - -
Racket :white_check_mark: :x: - -
Raku :white_check_mark: :x: - -
ReasonML :white_check_mark: :x: - -
Red :white_check_mark: :x: - -
Ruby :white_check_mark: :x: - 1
Rust :white_check_mark: :white_check_mark: 5 1
Scala :white_check_mark: :white_check_mark: 5 -
Scheme :white_check_mark: :x: - -
Standard ML :white_check_mark: :x: - -
Swift :white_check_mark: :x: - -
Tcl :white_check_mark: :x: - -
TypeScript :white_check_mark: :x: - -
Unison :white_check_mark: :x: - -
V :white_check_mark: :x: - -
Vim script :white_check_mark: :x: - -
Visual Basic :white_check_mark: :x: - -
WebAssembly :white_check_mark: :x: - -
Wren :white_check_mark: :x: - -
x86-64 Assembly :white_check_mark: :x: - -
Zig :white_check_mark: :x: - -

I’ll port leap for Common Lisp this weekend. I also promised Mark bottle-song a while back.

1 Like

Leap is in fact available on the Common Lisp track. It’s marked as status beta so maybe that’s why it got overlooked.

I will write an approach for C++. If I am too slow, or someone else has already done something, then please use the corresponding GitHub issue for further C+±related discussions.

It is. I’ll update my script

1 Like

We should mark the unpublished exercises nevertheless so non-maintaining students can actually see them.

I’ll post some thoughts on what might be interesting to discuss regarding this exercise. I’ll use separate posts to allow for people to easily reply to a single item.

These discussion points can be used for both the video Jeremy and I will be doing and as points to consider improving/fleshing out approaches with.

If you have any thoughts on my suggested discussion points of have other things to discuss, please let us know by posting them here in this topic.

Discuss: operator precedence

As the logic for determining whether a year is a leap year involves both AND and OR clauses, it is important to understand in which order these clauses are evaluated. This is known as operator precedence.

We could discuss:

  • Why do we need operator precedence?
  • Do all languages have operator precedence? (spoiler: nope! LISPs famously don’t have this “problem”)
  • Is operator precedence different between languages? (probably not for AND and OR)
  • How does operator precedence work applied to leap?

Discuss: modulo arithmetic

The classic way to determine whether a year can be divided by another number (4, 100 or 400 in the case of leap) is modulo arithmetic.

We could discuss:

  • What is modulo arithmetic?
  • How does it apply to leap?
1 Like

Discuss: short-circuiting

Most languages support AND and OR operators that are short-circuiting.

We could discuss:

  • What is short-circuiting?
  • What is the benefit of short-circuiting?
1 Like

Discuss: order of operations

There are three clauses in the algorithm, but does the order of these clauses matter?

We could discuss:

  • Is there an “optimal” order? (one that in general does the least amount of work)

@colinleach Has generously spiffied up the Python approach! Many thanks, Colin! :sparkles:

2 Likes

I’d be happy to draft an introduction and a few approaches to the exercise in either Elixir or Cojure if that’s helpful and nobody else is already working on it.

A draft PR for the Elixir track (work in progress, feedback welcomed)
A draft PR for the Clojure track (work in progress, please reopen)

3 Likes

Yes please!

Are we happy with implementing approaches by essentially copying from another track and adjusting the code samples?

Mostly copying was my initial approach when I offered to help. Then I looked at approaches in a few different tracks and quickly realised that the value of that might be limited unless the source language is very similar.

But copying might save time. Shouldn’t the approach depend on how much time a contributor has and how much time is left until the week?

Said that, after writing the Elixir approach to Leap, I’m planning to reuse large parts of it for Clojure…

In the video introducing 48in24 @iHiD suggests copying or using LLMs too.

I agree with @michalporeba’s answer for this. I think where languages are very similar with regards to the solution, then copying+pasting is basically gonna work great. So comparing the top two community solutions for Leap in C# and Ruby suggest this would be entirely copy/pastable from C# to Ruby:

Of the C# Approaches I think all of them could copy to Ruby just fine for Leap actually. Even the pattern matching one would work in latest Ruby.

But for other exercises I guess more work would be required. However, copy + paste via LLM definitely feels like it might be a very quick win. (I’m tempted to give maintainers a button to press that would generate a PR by taking one approach and transcribing it via ChatGPT to a different language - anyone interested?)

I tried last night using ChatGPT 4 to adapt what I have written for Elixir track to Clojure track. I thought the languages were similar enough, both functional. It was fast, and not necessarily incorrect, but not very useful either. I will have to do a lot of editing and proofreading before I submit a PR.

1 Like

I took a lot of inspiration from the Java Script track to implement the C++ material, which was reasonably fast to edit. I added some information from Eric’s suggestions, cut the JS-specific info, and will add a performance benchmark.
I also explored some more convoluted approaches. I should see and check what ChatGPT suggests on that front.

1 Like

An update from me on leap approaches for Elixir and Clojure.

Elixir is nearly ready to merge the first draft to see how it looks on the page. I believe it will be merged at some point today.

As for Clojure, I need a little bit of help. The pull request was automatically closed, as expected, but despite linking to this post, it was never reopened. Who maintains the Clojure track? Can @ErikSchierboom help? For now, the latest code/text is available here.

1 Like