-> replaced with =>, added -> (in) in reference_expression, reference -> reference_expression

This commit is contained in:
ProgramSnail 2023-07-19 11:01:02 +03:00
parent 8cc264fa5a
commit 567f75620d
4 changed files with 77 additions and 72 deletions

View file

@ -7,26 +7,26 @@ EdigitsDraft
:: math;
exec.main = {
%n := (?? os.args.size > 1 -> (<> os.args[1]).scan !!-> 27);
%n := (?? os.args.size > 1 => (<> os.args[1]).scan !!=> 27);
%k := binary_search 0;
%p & %q := sum_terms 0 (k - 1);
p += q;
$a := (std.BigInt.of 10).pow (n - 1);
%answer := p * a /. q;
%s := answer.to_string;
@ %i : (@ %j : 0..(n / 10 +. 1) -> j * 10) -> {
?? i + 10 <=. n ->
@ %i : (@ %j : 0..(n / 10 +. 1) => j * 10) => {
?? i + 10 <=. n =>
print (s.subseg i (i + 10) ++ "\t:" ++. (i + 10).to_string)
!!->
!!=>
print (s.subseg i n
++ (@ _ : 0..(10 - math.mod n 10) -> ''\s'')
++ (@ _ : 0..(10 - math.mod n 10) => ''\s'')
++ "\t:"
++ n.to_string);
};
}
sum_terms 'a 'b : Int Int -> std.BigInt -> std.BigInt = {
?? 'b ==. 'a + 1 -> return std.BigInt.of 1 & std.BigInt.of 'b;
?? 'b ==. 'a + 1 => return std.BigInt.of 1 & std.BigInt.of 'b;
%mid := 'a + 'b /. 2;
%p_left & %q_left := sum_terms 'a mid;
@ -38,20 +38,20 @@ sum_terms 'a 'b : Int Int -> std.BigInt -> std.BigInt = {
binary_search 'n : Int -> Int = {
%a := 0;
%b := 1;
@ not (test_k 'n b) -> {
@ not (test_k 'n b) => {
a = b;
b *= 2;
};
@ b - a >. 1 -> {
@ b - a >. 1 => {
%m := a + b /. 2;
?? test_k 'n m -> b = m !!-> a = m;
?? test_k 'n m => b = m !!=> a = m;
};
return b;
}
test_k 'n 'k : Int Int -> Bool = {
?? k < 0 -> return false;
?? k < 0 => return false;
%ln_k_factorial := k * (math.log k - 1) +. 0.5 * math.log math.tau;
%log_10_k_factorial := ln_k_factorial / math.ln10;
@ -83,7 +83,7 @@ test_k 'n 'k : Int Int -> Bool = {
(operator)
(number_literal))
(name_expression
(reference
(reference_expression
(array_access
(simple_name_identifier)
(number_literal)))