Add multilingual exercise code (#1959)

Replace the exercise pages' Python-only snippets with source-backed implementations for the 13 visible programming languages, and localize reader-facing comments by site language. Zig remains out of scope.

Approval bypass: repository protection requires one approval but does not enforce it for administrators. All 68 completed checks succeeded; four non-required Java jobs remained queued on the existing ubuntu-20.04 workflow, with no failed checks.
This commit is contained in:
Yudong Jin
2026-08-18 04:57:57 +08:00
committed by GitHub
parent bf86c39b6c
commit 28c1e74c1d
180 changed files with 5795 additions and 230 deletions
@@ -0,0 +1,55 @@
=begin
File: complexity_exercises.rb
Created Time: 2026-08-18
Author: Hello Algo Team
=end
### Iterative summation ###
def sum_iter(n)
res = 0
for i in 1..n
res += i
end
res
end
### Recursive summation ###
def sum_recur(n)
return 1 if n == 1
n + sum_recur(n - 1)
end
### Linear loop ###
def linear_loop(n)
res = 0
for i in 0...n
res += i
end
res
end
### Quadratic loop ###
def quadratic_loop(n)
res = 0
for i in 0...n
for j in i...n
res += j
end
end
res
end
### Logarithmic loop ###
def logarithmic_loop(n)
n /= 2 while n > 1
n
end
if __FILE__ == $0
raise 'sum check failed' unless sum_iter(1) == 1 && sum_recur(1) == 1
raise 'sum check failed' unless sum_iter(4) == 10 && sum_recur(4) == 10
raise 'linear check failed' unless linear_loop(4) == 6
raise 'quadratic check failed' unless quadratic_loop(4) == 20
raise 'logarithmic check failed' unless logarithmic_loop(4) == 1 && logarithmic_loop(5) == 1
end