Skip to content
View jrg94's full-sized avatar
πŸ’
Watching hockey
πŸ’
Watching hockey

Organizations

@TheRenegadeCoder

Block or report jrg94

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
jrg94/README.md

Welcome to My Profile!

This week's code snippet, Longest Common Subsequence in Elixir, is brought to you by Subete and the Sample Programs repo.

defmodule LongestCommonSubsequence do
  def main() do
    lcs = solve(System.argv())
    IO.puts("#{lcs}")
  end

  def solve([as, bs]) when is_bitstring(as) and is_bitstring(bs) do
    lcs(parse_string_to_list_integer(as), parse_string_to_list_integer(bs)) |> Enum.join(", ")
  end

  def solve(_) do
    print_usage()
  end

  def print_usage() do
    ~s(Usage: please provide two lists in the format "1, 2, 3, 4, 5")
  end

  def lcs([], _) do
    []
  end

  def lcs(_, []) do
    []
  end

  def lcs([a | as], [b | bs]) when a == b do
    [a] ++ lcs(as, bs)
  end

  def lcs([a | as], [b | bs]) do
    longest(lcs(as, [b | bs]), lcs([a | as], bs))
  end

  def longest(l1, l2) do
    if Enum.count(l1) > Enum.count(l2) do
      l1
    else
      l2
    end
  end

  def parse_string_to_list_integer(xs) do
    xs
    |> String.trim()
    |> String.split(",")
    |> Enum.map(&String.to_integer(String.trim(&1)))
  end
end

LongestCommonSubsequence.main()

Below you'll find an up-to-date list of articles by me on The Renegade Coder. For ease of browsing, emojis let you know the article category (i.e., blog: βœ’οΈ, code: πŸ’», meta: πŸ’­, teach: 🍎)

Also, here are some fun links you can use to support my work.


This document was automatically rendered on 2025-02-14 using SnakeMD.

Pinned Loading

  1. TheRenegadeCoder/sample-programs TheRenegadeCoder/sample-programs Public

    Sample Programs in Every Programming Language

    BASIC 585 591

  2. TheRenegadeCoder/how-to-python-code TheRenegadeCoder/how-to-python-code Public

    A collection of Jupyter Notebooks from the How to Python series

    Jupyter Notebook 85 28

  3. TheRenegadeCoder/SnakeMD TheRenegadeCoder/SnakeMD Public

    A markdown generation library for Python.

    Python 42 11

  4. TheRenegadeCoder/image-titler TheRenegadeCoder/image-titler Public

    An image title generator using The Renegade Coder style

    Python 17 6

  5. JuxtaMIDI JuxtaMIDI Public

    Pinpointing Mistakes in MIDI Practice Recordings

    JavaScript 16 2

  6. Orpheus Orpheus Public archive

    An adventure game with a focus on 3D audio

    Python 3