add: more samples and make them work
This commit is contained in:
44
samples/3np1.rpg
Normal file
44
samples/3np1.rpg
Normal file
@@ -0,0 +1,44 @@
|
||||
**FREE
|
||||
Ctl-Opt Main(ThreeNPlusOne);
|
||||
|
||||
Dcl-Proc ThreeNPlusOne;
|
||||
Dcl-S n Packed(10);
|
||||
Dcl-S counter Int(10) Inz(0);
|
||||
Dcl-S input_prompt VarChar(50) Inz('Enter a positive integer (or 0 to exit):');
|
||||
|
||||
// Use an infinite loop, exit when user enters 0
|
||||
Dow (1 = 1);
|
||||
Dsply input_prompt ' ' n;
|
||||
|
||||
If n = 0;
|
||||
Leave;
|
||||
EndIf;
|
||||
|
||||
If n < 0;
|
||||
input_prompt = 'Positive integers only. Enter a number:';
|
||||
Iter;
|
||||
EndIf;
|
||||
|
||||
// Start sequence calculation
|
||||
input_prompt = 'Enter a positive integer (or 0 to exit):'; // Reset prompt
|
||||
counter = 0;
|
||||
Dsply ('Sequence for ' + %Char(n) + ':');
|
||||
|
||||
Dow n > 1;
|
||||
If %Rem(n:2) = 0;
|
||||
// n is even, divide by 2
|
||||
n = n / 2;
|
||||
Else;
|
||||
// n is odd, multiply by 3 and add 1
|
||||
n = (n * 3) + 1;
|
||||
EndIf;
|
||||
|
||||
counter = counter + 1;
|
||||
Dsply %Char(n);
|
||||
EndDo;
|
||||
|
||||
Dsply ('Reached 1 in ' + %Char(counter) + ' iterations.');
|
||||
Dsply ' '; // Add a blank line for readability
|
||||
EndDo;
|
||||
|
||||
End-Proc ThreeNPlusOne;
|
||||
8
samples/3np1.rpg.golden
Normal file
8
samples/3np1.rpg.golden
Normal file
@@ -0,0 +1,8 @@
|
||||
DSPLY
|
||||
DSPLY Sequence for 8:
|
||||
DSPLY 4
|
||||
DSPLY 2
|
||||
DSPLY 1
|
||||
DSPLY Reached 1 in 3 iterations.
|
||||
DSPLY
|
||||
DSPLY
|
||||
18
samples/fizzbuzz.rpg
Normal file
18
samples/fizzbuzz.rpg
Normal file
@@ -0,0 +1,18 @@
|
||||
**FREE
|
||||
Ctl-Opt Main(FizzBuzz);
|
||||
|
||||
Dcl-Proc FizzBuzz;
|
||||
Dcl-S num Int(10);
|
||||
|
||||
For num = 1 To 100;
|
||||
If %Rem(num:3) = 0 And %Rem(num:5) = 0;
|
||||
Dsply ('num - ' + %Char(num) + ' FIZZBUZZ');
|
||||
ElseIf %Rem(num:3) = 0;
|
||||
Dsply ('num - ' + %Char(num) + ' FIZZ');
|
||||
ElseIf %Rem(num:5) = 0;
|
||||
Dsply ('num - ' + %Char(num) + ' BUZZ');
|
||||
Else;
|
||||
Dsply ('num - ' + %Char(num));
|
||||
EndIf;
|
||||
EndFor;
|
||||
End-Proc FizzBuzz;
|
||||
100
samples/fizzbuzz.rpg.golden
Normal file
100
samples/fizzbuzz.rpg.golden
Normal file
@@ -0,0 +1,100 @@
|
||||
DSPLY num - 1
|
||||
DSPLY num - 2
|
||||
DSPLY num - 3 FIZZ
|
||||
DSPLY num - 4
|
||||
DSPLY num - 5 BUZZ
|
||||
DSPLY num - 6 FIZZ
|
||||
DSPLY num - 7
|
||||
DSPLY num - 8
|
||||
DSPLY num - 9 FIZZ
|
||||
DSPLY num - 10 BUZZ
|
||||
DSPLY num - 11
|
||||
DSPLY num - 12 FIZZ
|
||||
DSPLY num - 13
|
||||
DSPLY num - 14
|
||||
DSPLY num - 15 FIZZBUZZ
|
||||
DSPLY num - 16
|
||||
DSPLY num - 17
|
||||
DSPLY num - 18 FIZZ
|
||||
DSPLY num - 19
|
||||
DSPLY num - 20 BUZZ
|
||||
DSPLY num - 21 FIZZ
|
||||
DSPLY num - 22
|
||||
DSPLY num - 23
|
||||
DSPLY num - 24 FIZZ
|
||||
DSPLY num - 25 BUZZ
|
||||
DSPLY num - 26
|
||||
DSPLY num - 27 FIZZ
|
||||
DSPLY num - 28
|
||||
DSPLY num - 29
|
||||
DSPLY num - 30 FIZZBUZZ
|
||||
DSPLY num - 31
|
||||
DSPLY num - 32
|
||||
DSPLY num - 33 FIZZ
|
||||
DSPLY num - 34
|
||||
DSPLY num - 35 BUZZ
|
||||
DSPLY num - 36 FIZZ
|
||||
DSPLY num - 37
|
||||
DSPLY num - 38
|
||||
DSPLY num - 39 FIZZ
|
||||
DSPLY num - 40 BUZZ
|
||||
DSPLY num - 41
|
||||
DSPLY num - 42 FIZZ
|
||||
DSPLY num - 43
|
||||
DSPLY num - 44
|
||||
DSPLY num - 45 FIZZBUZZ
|
||||
DSPLY num - 46
|
||||
DSPLY num - 47
|
||||
DSPLY num - 48 FIZZ
|
||||
DSPLY num - 49
|
||||
DSPLY num - 50 BUZZ
|
||||
DSPLY num - 51 FIZZ
|
||||
DSPLY num - 52
|
||||
DSPLY num - 53
|
||||
DSPLY num - 54 FIZZ
|
||||
DSPLY num - 55 BUZZ
|
||||
DSPLY num - 56
|
||||
DSPLY num - 57 FIZZ
|
||||
DSPLY num - 58
|
||||
DSPLY num - 59
|
||||
DSPLY num - 60 FIZZBUZZ
|
||||
DSPLY num - 61
|
||||
DSPLY num - 62
|
||||
DSPLY num - 63 FIZZ
|
||||
DSPLY num - 64
|
||||
DSPLY num - 65 BUZZ
|
||||
DSPLY num - 66 FIZZ
|
||||
DSPLY num - 67
|
||||
DSPLY num - 68
|
||||
DSPLY num - 69 FIZZ
|
||||
DSPLY num - 70 BUZZ
|
||||
DSPLY num - 71
|
||||
DSPLY num - 72 FIZZ
|
||||
DSPLY num - 73
|
||||
DSPLY num - 74
|
||||
DSPLY num - 75 FIZZBUZZ
|
||||
DSPLY num - 76
|
||||
DSPLY num - 77
|
||||
DSPLY num - 78 FIZZ
|
||||
DSPLY num - 79
|
||||
DSPLY num - 80 BUZZ
|
||||
DSPLY num - 81 FIZZ
|
||||
DSPLY num - 82
|
||||
DSPLY num - 83
|
||||
DSPLY num - 84 FIZZ
|
||||
DSPLY num - 85 BUZZ
|
||||
DSPLY num - 86
|
||||
DSPLY num - 87 FIZZ
|
||||
DSPLY num - 88
|
||||
DSPLY num - 89
|
||||
DSPLY num - 90 FIZZBUZZ
|
||||
DSPLY num - 91
|
||||
DSPLY num - 92
|
||||
DSPLY num - 93 FIZZ
|
||||
DSPLY num - 94
|
||||
DSPLY num - 95 BUZZ
|
||||
DSPLY num - 96 FIZZ
|
||||
DSPLY num - 97
|
||||
DSPLY num - 98
|
||||
DSPLY num - 99 FIZZ
|
||||
DSPLY num - 100 BUZZ
|
||||
Reference in New Issue
Block a user