Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Mutual-recursion/ABAP/mutual-recursion.abap
Normal file
47
Task/Mutual-recursion/ABAP/mutual-recursion.abap
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
report z_mutual_recursion.
|
||||
|
||||
class hoffstadter_sequences definition.
|
||||
public section.
|
||||
class-methods:
|
||||
f
|
||||
importing
|
||||
n type int4
|
||||
returning
|
||||
value(result) type int4,
|
||||
|
||||
m
|
||||
importing
|
||||
n type int4
|
||||
returning
|
||||
value(result) type int4.
|
||||
endclass.
|
||||
|
||||
|
||||
class hoffstadter_sequences implementation.
|
||||
method f.
|
||||
result = cond int4(
|
||||
when n eq 0
|
||||
then 1
|
||||
else n - m( f( n - 1 ) ) ).
|
||||
endmethod.
|
||||
|
||||
|
||||
method m.
|
||||
result = cond int4(
|
||||
when n eq 0
|
||||
then 0
|
||||
else n - f( m( n - 1 ) ) ).
|
||||
endmethod.
|
||||
endclass.
|
||||
|
||||
|
||||
start-of-selection.
|
||||
write: |{ reduce string(
|
||||
init results = |f(0 - 19): { hoffstadter_sequences=>f( 0 ) }|
|
||||
for i = 1 while i < 20
|
||||
next results = |{ results }, { hoffstadter_sequences=>f( i ) }| ) }|, /.
|
||||
|
||||
write: |{ reduce string(
|
||||
init results = |m(0 - 19): { hoffstadter_sequences=>m( 0 ) }|
|
||||
for i = 1 while i < 20
|
||||
next results = |{ results }, { hoffstadter_sequences=>m( i ) }| ) }|, /.
|
||||
Loading…
Add table
Add a link
Reference in a new issue