Ethiopian multiplication: Difference between revisions

Content added Content deleted
m (→‎{{header|Tiny BASIC}}: Moved to the BASIC section)
Line 1,114: Line 1,114:


578</pre>
578</pre>

==={{header|Tiny BASIC}}===
<lang tinybasic>
REM Ethiopian multiplication
LET X=17
LET Y=34
LET T=0
10 IF X<1 THEN GOTO 40
LET A=X
GOSUB 400
IF E=0 THEN GOTO 20
LET T=T+Y
PRINT X,", ",Y, " (kept)"
GOTO 30
20 PRINT X,", ",Y
30 GOSUB 300
LET X=A
LET A=Y
GOSUB 200
LET Y=A
GOTO 10
40 PRINT "------------"
PRINT "= ",T," (sum of kept second vals)"
END

REM Subroutines are required, though
REM they complicate the code
REM -- Double --
REM A - param.
200 LET A=2*A
RETURN
REM -- Halve --
REM A - param.
300 LET A=A/2
RETURN
REM -- Is even --
REM A - param.; E - result (0 - false)
400 LET E=A-(A/2)*2
RETURN
</lang>
{{out}}
<pre>
17, 34 (kept)
8, 68
4, 136
2, 272
1, 544 (kept)
------------
= 578 (sum of kept second vals)
</pre>


==={{header|True BASIC}}===
==={{header|True BASIC}}===
Line 5,355: Line 5,405:
1 544 KEPT
1 544 KEPT
17 * 34 = 578
17 * 34 = 578

=={{header|Tiny BASIC}}==
<lang tinybasic>
REM Ethiopian multiplication
LET X=17
LET Y=34
LET T=0
10 IF X<1 THEN GOTO 40
LET A=X
GOSUB 400
IF E=0 THEN GOTO 20
LET T=T+Y
PRINT X,", ",Y, " (kept)"
GOTO 30
20 PRINT X,", ",Y
30 GOSUB 300
LET X=A
LET A=Y
GOSUB 200
LET Y=A
GOTO 10
40 PRINT "------------"
PRINT "= ",T," (sum of kept second vals)"
END

REM Subroutines are required, though
REM they complicate the code
REM -- Double --
REM A - param.
200 LET A=2*A
RETURN
REM -- Halve --
REM A - param.
300 LET A=A/2
RETURN
REM -- Is even --
REM A - param.; E - result (0 - false)
400 LET E=A-(A/2)*2
RETURN
</lang>
{{out}}
<pre>
17, 34 (kept)
8, 68
4, 136
2, 272
1, 544 (kept)
------------
= 578 (sum of kept second vals)
</pre>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==