Skip to content

Releases: kmyk-jikka/Jikka

v5.0.9.0

14 Jul 11:37
a063d2f
Compare
Choose a tag to compare
  • The generated C++ stops being functional and becomes natural.
  • The restricted Python allows to write main function and uses it to analyze input/output format.

Input:

# https://atcoder.jp/contests/dp/tasks/dp_a
from typing import *

def solve(n: int, h: List[int]) -> int:
    assert 2 <= n <= 10 ** 5
    assert len(h) == n
    assert all(1 <= h_i <= 10 ** 4 for h_i in h)

    dp = [-1 for _ in range(n)]
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, n):
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
    return dp[n - 1]

def main() -> None:
    n = int(input())
    h = list(map(int, input().split()))
    assert len(h) == n
    ans = solve(n, h)
    print(ans)

if __name__ == '__main__':
    main()

Output (https://atcoder.jp/contests/dp/submissions/24221651):

#include "jikka/all.hpp"
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
int64_t solve(int64_t n_0, std::vector<int64_t> h_1) {
  int64_t x6;
  if (n_0 + -1 == 0) {
    x6 = 0;
  } else {
    std::vector<std::array<int64_t, 2>> x2 =
        std::vector<std::array<int64_t, 2>>(n_0 + -2 + 1);
    x2[0] = jikka::make_array<int64_t>(
        0, std::max<int64_t>(-h_1[0] + h_1[1], h_1[0] + -h_1[1]));
    for (int32_t i3 = 0; i3 < int32_t(n_0 + -2); ++i3) {
      x2[(i3 + 1)] = jikka::make_array<int64_t>(
          x2[i3][1],
          std::min<int64_t>(
              x2[i3][1] + std::max<int64_t>(-h_1[(i3 + 1)] + h_1[(i3 + 2)],
                                            h_1[(i3 + 1)] + -h_1[(i3 + 2)]),
              x2[i3][0] + std::max<int64_t>(-h_1[i3] + h_1[(i3 + 2)],
                                            h_1[i3] + -h_1[(i3 + 2)])));
    }
    x6 = x2[(n_0 + -2)][1];
  }
  return x6;
}
int main() {
  int64_t n_7 = -1;
  std::cin >> n_7;
  std::vector<int64_t> h_8 = std::vector<int64_t>(n_7, -1);
  for (int32_t i9 = 0; i9 < n_7; ++i9) {
    std::cin >> h_8[i9];
  }
  auto ans_10 = solve(n_7, h_8);
  std::cout << ans_10 << ' ';
  std::cout << '\n' << ' ';
}

v5.0.8.0

11 Jul 13:19
1f33219
Compare
Choose a tag to compare

Some optimizers are added.
Now it can use cumulative sums.

Input:

# https://judge.yosupo.jp/problem/static_range_sum

from typing import *

def solve(n: int, q: int, a: List[int], l: List[int], r: List[int]) -> List[int]:
    ans = [-1 for _ in range(q)]
    for i in range(q):
        ans[i] = sum(a[l[i]:r[i]])
    return ans

Output:

std::vector<int64_t> solve(int64_t n_1653, int64_t q_1654,
                           std::vector<int64_t> a_1655,
                           std::vector<int64_t> l_1656,
                           std::vector<int64_t> r_1657) {
  std::vector<int64_t> x1658 = jikka::scanl<int64_t, int64_t>(
      [=](int64_t b1659) -> std::function<int64_t(int64_t)> {
        return [=](int64_t b1660) -> int64_t { return b1659 + b1660; };
      },
      0, a_1655);
  return jikka::fmap<int64_t, int64_t>(
      [=](int64_t b1661) -> int64_t {
        return x1658[(r_1657[b1661] + (-l_1656[b1661] + l_1656[b1661]))] +
               -x1658[l_1656[b1661]];
      },
      jikka::range1(q_1654));
}

v5.0.7.0

09 Jul 05:36
bf4def6
Compare
Choose a tag to compare
v5.0.7.0 Pre-release
Pre-release

Many internal cleanups are done.

Now our core language is very close to GHC' Core.
It's curried and has a system for rewrite-rules.

v5.0.6.0

28 Jun 18:31
84f57f8
Compare
Choose a tag to compare

Error reporting and error recovery are improved.

Input:

def solve(n: int) -> bool:
    a = n + True  # err
    b = 2 * n
    return b  # err

Output:

Type Error (line 2 column 13) (user's mistake?): Jikka.RestrictedPython.Convert.TypeInfer: failed to solve type equations: failed to unify type int and type bool: type int is not type bool
1 |def solve(n: int) -> bool:
2 |    a = n + True  # err
               ^^^^
3 |    b = 2 * n

Type Error (line 4 column 12) (user's mistake?): Jikka.RestrictedPython.Convert.TypeInfer: failed to solve type equations: failed to unify type bool and type int: type bool is not type int
3 |    b = 2 * n
4 |    return b  # err
              ^

contributions:

v5.0.5.0

25 Jun 11:52
ac95068
Compare
Choose a tag to compare

Some optimizations are implemented.
Now it can convert a O(N) Python code for fibonacci to O(log N) C++ code.

Input, O(N):

def f(n: int) -> int:
    a = 0
    b = 1
    for _ in range(n):
        c = a + b
        a = b
        b = c
    return a

def solve(n: int) -> int:
    return f(n) % 1000000007

Output, O(log N):

#include "jikka/all.hpp"
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
int64_t solve(int64_t n_317) {
  return jikka::modmatap<2, 2>(
      jikka::modmatpow<2>(jikka::make_array<std::array<int64_t, 2>>(
                              jikka::make_array<int64_t>(1, 1),
                              jikka::make_array<int64_t>(1, 0)),
                          n_317, 1000000007),
      jikka::make_array<int64_t>(1, 0), 1000000007)[1];
}
int main() {
  int64_t x318;
  std::cin >> x318;
  int64_t x319 = solve(x318);
  std::cout << x319;
  std::cout << '\n';
}

v5.0.4.0

23 Jun 07:31
1c3376d
Compare
Choose a tag to compare
Merge pull request #20 from kmyk/develop

v5.0.4.0

v5.0.3.0

23 Jun 04:28
a21d38b
Compare
Choose a tag to compare
v5.0.3.0 Pre-release
Pre-release
Merge pull request #18 from kmyk/develop

v5.0.3.0

v5.0.2.0

19 Jun 21:43
d445440
Compare
Choose a tag to compare
v5.0.2.0 Pre-release
Pre-release
Merge pull request #17 from kmyk/fix-version

chore: Fix the version to v5.0.2.0

v5.0.1.0

03 Dec 13:22
Compare
Choose a tag to compare
RELEASE: v5.0.1.0

v4

03 Dec 13:09
Compare
Choose a tag to compare
v4
Add Haskell codes as samples of real-world codes