interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / hailstone-sequence.wiki

95 lines · 1747 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8text t1 "hailstone(27) has "
9text t2 " elements:"
10text dots " ..."
11text t3 "below 100000 the longest is "
12text t4 " with "
13text t5 " elements\n"
14global seq ulong 1000
15note emit writes every byte of a to stdout; a short write is retried, an error exits 1
16fn emit a view uchar * to void
17o = ulong 0
18while lt o len a bound 4096
19k = write 1 a o sub len a o
20if le k 0
21exit 1
22end
23o = add o ulong k
24end
25end
26note emitu writes n in decimal; 20 digits hold every ulong
27fn emitu n ulong to void
28d = new uchar 20 0
29i = ulong 20
30v = n
31while true bound 20
32i = sub i 1
33put d i uchar add rem v 10 48
34v = div v 10
35if eq v 0
36break
37end
38end
39emit part d i sub 20 i
40end
41note hfill stores the sequence from n in seq and returns its length; every start below 100000
42note reaches 1 in at most 351 elements, so 999 steps is a proof-backed bound (more traps 4)
43fn hfill n ulong to ulong
44c = ulong 1
45v = n
46put seq 0 v
47while ne v 1 bound 999
48if eq rem v 2 0
49v = div v 2
50else
51v = add mul v 3 1
52end
53put seq c v
54c = add c 1
55end
56ret c
57end
58fn main to int
59c = hfill 27
60emit t1
61emitu c
62emit t2
63for i ulong 4
64emit sp
65emitu get seq i
66end
67emit dots
68for i ulong 4
69emit sp
70emitu get seq add sub c 4 i
71end
72emit nl
73best = ulong 1
74bl = ulong 1
75for i ulong 99999
76n = add i 1
77l = hfill n
78if gt l bl
79bl = l
80best = n
81end
82end
83emit t3
84emitu best
85emit t4
86emitu bl
87emit t5
88ret 0
89end
90</syntaxhighlight>
91{{out}}
92<pre>
93hailstone(27) has 112 elements: 27 82 41 124 ... 8 4 2 1
94below 100000 the longest is 77031 with 351 elements
95</pre>