Hailstone sequence: Difference between revisions

m (→‎{{header|Dart}}: Brought Dart code up to date)
Line 8,654:
</syntaxhighlight>
 
=={{header|RPL}}==
HP-28 emulator's timedog preventing from longlasting code execution, the third item of the task is achieved by calculating the 1-100,000 sequence in increments of 5,000 numbers, with a derivative of the generator that only provides the length of the sequence to increase execution speed.
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! Code
! Comments
|-
|
DUP 1 →LIST SWAP
'''WHILE''' DUP 1 ≠ '''REPEAT'''
'''IF''' DUP 2 MOD '''THEN''' 3 * 1 + '''ELSE''' 2 / '''END'''
SWAP OVER + SWAP
'''END''' DROP
≫ 'SYRAQ' STO
1 SWAP '''WHILE''' DUP 1 ≠ '''REPEAT'''
'''IF''' DUP 2 MOD '''THEN''' 3 * 1 + '''ELSE''' 2 / '''END'''
SWAP 1 + SWAP
'''END''' DROP
≫ 'SYRAF' STO
≪ SyMax SYRAF SWAP
DUP 5000 + DUP 4 ROLLD '''FOR''' n
'''IF''' DUP n SYRAF <
'''THEN'''
DROP n SYRAF n 'SyMax' STO
'''END NEXT''' DROP ≫
'SYR5K' STO
|
''( n -- { sequence } )''
initialize sequence with n
Calculate next element
Store it into sequence
Forget n
''( n -- sequence_length )''
Initialize counter
Calculate next element
Increment counter
Forget n
''( n -- n+10000 )''
Initialize loop
If sequence length greater than previous ones...
... memorize n
|}
The following instructions deliver what is required:
27 SYRAQ SIZE
1 SYR5K … SYR5K [20 times] DROP SyMax RCL
{{out}}
<pre>
2: 127
1: 77031
</pre>
=={{header|Ruby}}==
This program uses new methods (Integer#even? and Enumerable#max_by) from Ruby 1.8.7.
1,150

edits