{"text": "# Here we use generators : the given formula doesn't need one, but the alternate\n# non-squares function is better done with a generator.\n\n# The formula is implemented with exact floor(sqrt(n)), so we use\n# a trick: multiply by 100 to get the first decimal digit of the\n# square root of n, then add 5 (that's 1/2 multiplied by 10).\n# Then just divide by 10 to get floor(1/2 + sqrt(n)) exactly.\n# It looks weird, but unlike floating point, it will do the job\n# for any n.\nNonSquaresGen := function()\n\tlocal ns, n;\n\tn := 0;\n\tns := function()\n\t\tn := n + 1;\n\t\treturn n + QuoInt(5 + RootInt(100*n), 10);\n\tend;\n\treturn ns;\nend;\n\nNonSquaresAlt := function()\n\tlocal ns, n, q, k;\n\tn := 1;\n\tq := 4;\n\tk := 3;\n\tns := function()\n\t\tn := n + 1;\n\t\tif n = q then\n\t\t\tn := n + 1;\n\t\t\tk := k + 2;\n\t\t\tq := q + k;\n\t\tfi;\n\t\treturn n;\n\tend;\n\treturn ns;\nend;\n\ngen := NonSquaresGen();\nList([1 .. 22] i -> gen());\n# [ 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27 ]\n\na := NonSquaresGen();\nb := NonSquaresAlt();\n\nForAll([1 .. 1000000], i -> a() = b());\n# true\n", "meta": {"hexsha": "40cb98e42b3c6c4ad70b1461394677cadc41e1d7", "size": 1064, "ext": "gap", "lang": "GAP", "max_stars_repo_path": "Task/Sequence-of-non-squares/GAP/sequence-of-non-squares.gap", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sequence-of-non-squares/GAP/sequence-of-non-squares.gap", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sequence-of-non-squares/GAP/sequence-of-non-squares.gap", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.1304347826, "max_line_length": 86, "alphanum_fraction": 0.5939849624, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.8962513648201266, "lm_q1q2_score": 0.849784791949494}}
{"text": "CollatzSequence := function(n)\n  local v;\n  v := [ n ];\n  while n > 1 do\n    if IsEvenInt(n) then\n      n := QuoInt(n, 2);\n    else\n      n := 3*n + 1;\n    fi;\n    Add(v, n);\n  od;\n  return v;\nend;\n\nCollatzLength := function(n)\n  local m;\n  m := 1;\n  while n > 1 do\n    if IsEvenInt(n) then\n      n := QuoInt(n, 2);\n    else\n      n := 3*n + 1;\n    fi;\n    m := m + 1;\n  od;\n  return m;\nend;\n\nCollatzMax := function(a, b)\n  local n, len, nmax, lmax;\n  lmax := 0;\n  for n in [a .. b] do\n    len := CollatzLength(n);\n    if len > lmax then\n      nmax := n;\n      lmax := len;\n    fi;\n  od;\n  return [ nmax, lmax ];\nend;\n\nCollatzSequence(27);\n# [ 27, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206,\n#   103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502,\n#   251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429,\n#   7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732, 866, 433, 1300,\n#   650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1 ]\nCollatzLength(27);\n# 112\n\nCollatzMax(1, 100);\n# [ 97, 119 ]\nCollatzMax(1, 1000);\n# [ 871, 179 ]\nCollatzMax(1, 10000);\n# [ 6171, 262 ]\nCollatzMax(1, 100000);\n# [ 77031, 351 ]\nCollatzMax(1, 1000000);\n# [ 837799, 525 ]\n", "meta": {"hexsha": "670ae2b5c4463b9a89590d517c42b2fce9091983", "size": 1433, "ext": "gap", "lang": "GAP", "max_stars_repo_path": "Task/Hailstone-sequence/GAP/hailstone-sequence.gap", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Hailstone-sequence/GAP/hailstone-sequence.gap", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Hailstone-sequence/GAP/hailstone-sequence.gap", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.4918032787, "max_line_length": 117, "alphanum_fraction": 0.5436147941, "num_tokens": 720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8824278772763471, "lm_q1q2_score": 0.8324362034911286}}
{"text": "Catalan1 := n -> Binomial(2*n, n) - Binomial(2*n, n - 1);\n\nCatalan2 := n -> Binomial(2*n, n)/(n + 1);\n\nCatalan3 := function(n)\n    local k, c;\n    c := 1;\n    k := 0;\n    while k < n do\n        k := k + 1;\n        c := 2*(2*k - 1)*c/(k + 1);\n    od;\n    return c;\nend;\n\nCatalan4_memo := [1];\nCatalan4 := function(n)\n    if not IsBound(Catalan4_memo[n + 1]) then\n        Catalan4_memo[n + 1] := Sum([0 .. n - 1], i -> Catalan4(i)*Catalan4(n - 1 - i));\n    fi;\n    return Catalan4_memo[n + 1];\nend;\n\n\n# The first fifteen: 0 to 14 !\nList([0 .. 14], Catalan1);\nList([0 .. 14], Catalan2);\nList([0 .. 14], Catalan3);\nList([0 .. 14], Catalan4);\n# Same output for all four:\n# [ 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440 ]\n", "meta": {"hexsha": "3ae014680436aa9d94f3281e87688945497f09b2", "size": 752, "ext": "gap", "lang": "GAP", "max_stars_repo_path": "Task/Catalan-numbers/GAP/catalan-numbers.gap", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Catalan-numbers/GAP/catalan-numbers.gap", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Catalan-numbers/GAP/catalan-numbers.gap", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.5, "max_line_length": 88, "alphanum_fraction": 0.5252659574, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9793540668504083, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.8139833322469502}}
{"text": "Eratosthenes := function(n)\n    local a, i, j;\n    a := ListWithIdenticalEntries(n, true);\n    if n < 2 then\n        return [];\n    else\n        for i in [2 .. n] do\n            if a[i] then\n                j := i*i;\n                if j > n then\n                    return Filtered([2 .. n], i -> a[i]);\n                else\n                    while j <= n do\n                        a[j] := false;\n                        j := j + i;\n                    od;\n                fi;\n            fi;\n        od;\n    fi;\nend;\n\nEratosthenes(100);\n\n[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 ]\n", "meta": {"hexsha": "08e0232d7c093836b4f7e3a7619e93d01713e8dc", "size": 642, "ext": "gap", "lang": "GAP", "max_stars_repo_path": "Task/Sieve-of-Eratosthenes/GAP/sieve-of-eratosthenes.gap", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sieve-of-Eratosthenes/GAP/sieve-of-eratosthenes.gap", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sieve-of-Eratosthenes/GAP/sieve-of-eratosthenes.gap", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 24.6923076923, "max_line_length": 98, "alphanum_fraction": 0.3457943925, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9732407191430025, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.8131266024694257}}
