Ethiopian multiplication: Difference between revisions

m
imported>Maxima enthusiast
No edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 977:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
Same code as [[#Nascom_BASIC|Nascom BASIC]]
 
==={{header|ASIC}}===
Line 1,069 ⟶ 1,071:
FUNCTION isEven% (a AS INTEGER)
isEven% = (a MOD 2) - 1
END FUNCTION</syntaxhighlight>{{out}}
{{out}}
<pre> 17 34
8
4
2
1 544
= 578</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256vbnet">outP = 0
x = 17
y = 34
Line 1,131 ⟶ 1,134:
DEF FNhalve(A%) = A% DIV 2
DEF FNeven(A%) = ((A% AND 1) = 0)</syntaxhighlight>{{out}}
{{out}}
<pre> 17 34
8 ---
4 ---
Line 1,138 ⟶ 1,142:
1 544
===
578</pre>
 
==={{header|Chipmunk Basic}}===
{{trans|BASIC256}}
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="textvbnet">100 sub doub(a)
110 doub = a*2
120 end sub
130 sub half(a)
140 half = int(a/2)
150 end sub
160 sub iseven(a)
170 iseven = (a mod 2)-1
180 end sub
190 outp = 0
200 x = 17
210 y = 34
220 while x >= 1
230 print ""x;chr$(9);
240 if not (iseven(x)) then
250 outp = outp - y
260 print y
270 else
280 print
290 endif
300 if x < 2 then exit while
310 x = half(x)
320 y = 2 * doub(y)
330 wend
340 print "=";chr$(9);outp
350 end</syntaxhighlight>
 
==={{header|FreeBASIC}}===
Line 1,229 ⟶ 1,263:
Sleep
</syntaxhighlight>note: algorithm uses strings instead of integers
{{out}}
{{out}}<pre>Half Double * marks those accumulated
Biggest Smallest
 
Line 1,298 ⟶ 1,333:
doubleInt = Int(num * 2)
End Function</syntaxhighlight>
 
 
==={{header|Microsoft Small Basic}}===
<syntaxhighlight lang="microsoftsmallbasic">x = 17
x = 17
y = 34
tot = 0
Line 1,319 ⟶ 1,352:
TextWindow.Write("=")
TextWindow.CursorLeft = 10
TextWindow.WriteLine(tot)</syntaxhighlight>
</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
<syntaxhighlight lang="gwbasic">10 REM Ethiopian multiplication
10 REM Ethiopian multiplication
20 DEF FND(A) = 2*A
30 DEF FNH(A) = INT(A/2)
Line 1,342 ⟶ 1,373:
170 PRINT "------------"
180 PRINT "= "; TAB(9); T; "(sum of kept second vals)"
190 END</syntaxhighlight>
 
</syntaxhighlight>
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
Same code as [[#Nascom_BASIC|Nascom BASIC]]
 
==={{header|Nascom BASIC}}===
{{trans|Modula-2}}
{{works with|Nascom ROM BASIC|4.7}}
<syntaxhighlight lang="basic">10 REM Ethiopian multiplication
10 REM Ethiopian multiplication
20 DEF FND(A)=2*A
30 DEF FNH(A)=INT(A/2)
Line 1,369 ⟶ 1,402:
1000 S$=STR$(NR)
1010 PRINT SPC(9-LEN(S$));S$;
1020 RETURN</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre> 17 34
17 34
8
4
2
1 544
= 578</pre>
</pre>
 
==={{header|PureBasic}}===
Line 1,457 ⟶ 1,487:
EndIf</syntaxhighlight>
{{out}}
<pre> Ethiopian multiplication of 17 and 34 ... equals 578
Ethiopian multiplication of -17 and 34 ... equals -578
Ethiopian multiplication of -17 and -34 ... equals 578</pre>
 
==={{header|QB64}}===
Line 1,488 ⟶ 1,518:
END FUNCTION</syntaxhighlight>
{{out}}
<pre>578</pre>
578
</pre>
 
==={{header|Sinclair ZX81 BASIC}}===
Line 1,581 ⟶ 1,609:
REM A - param.; E - result (0 - false)
400 LET E=A-(A/2)*2
RETURN </syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>17, 34 (kept)
17, 34 (kept)
8, 68
4, 136
Line 1,591 ⟶ 1,617:
1, 544 (kept)
------------
= 578 (sum of kept second vals)</pre>
</pre>
 
==={{header|True BASIC}}===
A translation of BBC BASIC. True BASIC does not have Boolean operations built-in.
<syntaxhighlight lang="basic">!RosettaCode: Ethiopian Multiplication
!RosettaCode: Ethiopian Multiplication
! True BASIC v6.007
PROGRAM EthiopianMultiplication
Line 1,625 ⟶ 1,649:
DEF FNhalve(A) = INT(A / 2)
DEF FNeven(A) = MOD(A+1,2)
END</syntaxhighlight>
END
 
</syntaxhighlight>
 
==={{header|XBasic}}===
{{trans|Modula-2}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">' Ethiopian multiplication
' Ethiopian multiplication
PROGRAM "ethmult"
VERSION "0.0000"
Line 1,673 ⟶ 1,694:
RETURN a&& MOD 2 = 0
END FUNCTION
END PROGRAM</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre> 17 34
17 34
8
4
2
1 544
= 578</pre>
</pre>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasicvbnet">outP = 0
x = 17
y = 34
Line 2,489 ⟶ 2,507:
 
=={{header|EasyLang}}==
</syntaxhighlight>
{{trans|Microsoft Small Basic}}
func mult x y .
<syntaxhighlight lang="text">
while x >= 171
if 17x mod 2 <> 340
y = 34
tot += 0y
x = x div 2.
while x >= 1
write x = x &div "\t"2
if (x + 1) mod 2y *= 02
tot += y.
return print ytot
else
print ""
.
x = x div 2
y = 2 * y
.
print "=\t"mult &17 tot34
</syntaxhighlight>
 
Line 6,646 ⟶ 6,659:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var halve = Fn.new { |n| (n/2).truncate }
 
var double = Fn.new { |n| n * 2 }
1,990

edits