-
Notifications
You must be signed in to change notification settings - Fork 469
Open
Description
Reproducing the behavior
Here is the related minimal example:
def max(a: u24, b: u24) -> u24:
if a > b:
return a
else:
return b
def collatz_len_and_peak(x: u24) -> (u24, u24):
def go(n: u24, steps: u24, peak: u24) -> (u24, u24):
if n == 1:
return (steps, peak)
else:
if (n % 2) == 0:
next = n / 2
else:
next = 3 * n + 1
new_peak = max(peak, next)
return go(next, steps + 1, new_peak)
return go(x, 0, x)
def scan_upto(n: u24) -> (u24, u24, u24, u24):
def scan_range(start: u24, end: u24) -> (u24, u24, u24, u24):
if start > end:
return (1, 0, 1, 0)
elif start == end:
(steps, peak) = collatz_len_and_peak(start)
return (start, steps, peak, steps)
else:
mid = (start + end) / 2
(best_n1, best_steps1, best_peak1, xor_steps1) = scan_range(start, mid)
(best_n2, best_steps2, best_peak2, xor_steps2) = scan_range(mid + 1, end)
def choose_best(steps1: u24, n1: u24, peak1: u24, steps2: u24, n2: u24, peak2: u24) -> (u24, u24, u24):
if steps2 > steps1:
return (n2, steps2, peak2)
else:
return (n1, steps1, peak1)
(best_n, best_steps, best_peak) = choose_best(best_steps1, best_n1, best_peak1, best_steps2, best_n2, best_peak2)
xor_steps = xor_steps1 ^ xor_steps2
return (best_n, best_steps, best_peak, xor_steps)
return scan_range(1, n)
def main() -> IO(u24):
with IO:
n = 1000000
(best_n, best_steps, best_peak, xor_steps) = scan_upto(n)
* <- IO/print(String.concat("n*=", String.from_num(best_n)))
* <- IO/print("\n")
* <- IO/print(String.concat("steps=", String.from_num(best_steps)))
* <- IO/print("\n")
* <- IO/print(String.concat("peak=", String.from_num(best_peak)))
* <- IO/print("\n")
* <- IO/print(String.concat("xor_steps=", String.from_num(xor_steps)))
* <- IO/print("\n")
return wrap(0)
I get this error:
In main.bend :
In definition 'main':
Unbound variable 'String.concat'.
Unbound variable 'String.from_num'.
Expected output is:
n*=837799
steps=524
peak=2974984576
xor_steps=880
This error seems very unrelated.
System Settings
Example:
- HVM: idk ?
- Bend: 0.2.37
- OS: Nixos
- CPU: i7-1065G7
- GPU: None
- Cuda Version None
Additional context
Trying to implement the same algorithm using multiple languages at the moment but massively parralel languages are a bit hard for me :(
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels