A+B: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
|||
Line 30: | Line 30: | ||
|} |
|} |
||
<br><br> |
<br><br> |
||
=={{header|0815}}== |
|||
<lang 0815>|x|+%</lang> |
|||
=={{header|11l}}== |
=={{header|11l}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
<lang 11l>print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))</lang> |
<lang 11l>print(sum(input().split(‘ ’, group_delimiters' 1B).map(i -> Int(i))))</lang> |
||
=={{header|0815}}== |
|||
<lang 0815>|x|+%</lang> |
|||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
Line 277: | Line 277: | ||
</lang> |
</lang> |
||
=={{header|ABAP}}== |
=={{header|ABAP}}== |
||
<lang ABAP>report z_sum_a_b. |
<lang ABAP>report z_sum_a_b. |
||
Line 1,096: | Line 1,097: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang awk>{print $1 + $2}</lang> |
<lang awk>{print $1 + $2}</lang> |
||
=={{header|Batch File}}== |
|||
Prompts version |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set /p a="A: " |
|||
set /p b="B: " |
|||
set /a c=a+b |
|||
echo %c% |
|||
endlocal</lang> |
|||
All on the commandline version |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set a=%1 |
|||
set b=%2 |
|||
set /a c=a+b |
|||
echo %c% |
|||
endlocal</lang> |
|||
Formula on the command line version |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set /a c=%~1 |
|||
echo %c% |
|||
endlocal</lang> |
|||
Example of 'Formula on the command line version' |
|||
<pre> |
|||
>aplusb 123+456 |
|||
579 |
|||
>aplusb "1+999" |
|||
1000 |
|||
</pre> |
|||
Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt) |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set /p a="Input stream: " |
|||
call :add %a% |
|||
echo %res% |
|||
endlocal |
|||
goto :eof |
|||
:add |
|||
set /a res=res+%1 |
|||
shift |
|||
if "%1" neq "" goto :add</lang> |
|||
Example of 'parse the input stream version' |
|||
<pre>>aplusb |
|||
Input stream: 1234 5678 |
|||
6912 |
|||
>aplusb |
|||
Input stream: 123 234 345 456 567 678 789 890 |
|||
4082</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
Line 1,271: | Line 1,217: | ||
50 GOTO 30 |
50 GOTO 30 |
||
60 PRINT VAL A$( TO I-1)+VAL A$(I+1 TO )</lang> |
60 PRINT VAL A$( TO I-1)+VAL A$(I+1 TO )</lang> |
||
=={{header|Batch File}}== |
|||
Prompts version |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set /p a="A: " |
|||
set /p b="B: " |
|||
set /a c=a+b |
|||
echo %c% |
|||
endlocal</lang> |
|||
All on the commandline version |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set a=%1 |
|||
set b=%2 |
|||
set /a c=a+b |
|||
echo %c% |
|||
endlocal</lang> |
|||
Formula on the command line version |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set /a c=%~1 |
|||
echo %c% |
|||
endlocal</lang> |
|||
Example of 'Formula on the command line version' |
|||
<pre> |
|||
>aplusb 123+456 |
|||
579 |
|||
>aplusb "1+999" |
|||
1000 |
|||
</pre> |
|||
Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt) |
|||
<lang dos>::aplusb.cmd |
|||
@echo off |
|||
setlocal |
|||
set /p a="Input stream: " |
|||
call :add %a% |
|||
echo %res% |
|||
endlocal |
|||
goto :eof |
|||
:add |
|||
set /a res=res+%1 |
|||
shift |
|||
if "%1" neq "" goto :add</lang> |
|||
Example of 'parse the input stream version' |
|||
<pre>>aplusb |
|||
Input stream: 1234 5678 |
|||
6912 |
|||
>aplusb |
|||
Input stream: 123 234 345 456 567 678 789 890 |
|||
4082</pre> |
|||
=={{header|bc}}== |
=={{header|bc}}== |
||
Line 1,685: | Line 1,686: | ||
The question mark ''?'' reads and executes a line of input. The user must enter a dc program that pushes two numbers to the stack, such as ''2 3'' or ''5 _1''. (The user must use underscore ''_'' for negative numbers.) |
The question mark ''?'' reads and executes a line of input. The user must enter a dc program that pushes two numbers to the stack, such as ''2 3'' or ''5 _1''. (The user must use underscore ''_'' for negative numbers.) |
||
=={{header|DCL}}== |
=={{header|DCL}}== |
||
<lang DCL>$ read sys$command line |
<lang DCL>$ read sys$command line |
||
Line 1,690: | Line 1,692: | ||
$ b = f$element( 1, " ", line ) |
$ b = f$element( 1, " ", line ) |
||
$ write sys$output a, "+", b, "=", a + b</lang> |
$ write sys$output a, "+", b, "=", a + b</lang> |
||
=={{header|Déjà Vu}}== |
|||
{{trans|Python}} |
|||
===Console=== |
|||
<lang dejavu>0 |
|||
for k in split !prompt "" " ": |
|||
+ to-num k |
|||
!print</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
Line 1,738: | Line 1,732: | ||
var b := StrToInt(InputBox('A+B', 'Enter 2nd number', '0')); |
var b := StrToInt(InputBox('A+B', 'Enter 2nd number', '0')); |
||
ShowMessage('Sum is '+IntToStr(a+b));</lang> |
ShowMessage('Sum is '+IntToStr(a+b));</lang> |
||
=={{header|Déjà Vu}}== |
|||
{{trans|Python}} |
|||
===Console=== |
|||
<lang dejavu>0 |
|||
for k in split !prompt "" " ": |
|||
+ to-num k |
|||
!print</lang> |
|||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
Line 1,924: | Line 1,926: | ||
-864 |
-864 |
||
</pre> |
</pre> |
||
=={{header|EGL}}== |
|||
<lang EGL> |
|||
package programs; |
|||
// basic program |
|||
// |
|||
program AplusB type BasicProgram {} |
|||
function main() |
|||
try |
|||
arg1 string = SysLib.getCmdLineArg(1); |
|||
arg2 string = SysLib.getCmdLineArg(2); |
|||
int1 int = arg1; |
|||
int2 int = arg2; |
|||
sum int = int1 + int2; |
|||
SysLib.writeStdout("sum1: " + sum); |
|||
onException(exception AnyException) |
|||
SysLib.writeStdout("No valid input. Provide 2 integer numbers as arguments to the program."); |
|||
end |
|||
end |
|||
end |
|||
</lang> |
|||
=={{header|Eiffel}}== |
=={{header|Eiffel}}== |
||
Line 2,096: | Line 2,121: | ||
printf(1," %d\n",a+b)</lang> |
printf(1," %d\n",a+b)</lang> |
||
=={{header|EGL}}== |
|||
<lang EGL> |
|||
package programs; |
|||
// basic program |
|||
// |
|||
program AplusB type BasicProgram {} |
|||
function main() |
|||
try |
|||
arg1 string = SysLib.getCmdLineArg(1); |
|||
arg2 string = SysLib.getCmdLineArg(2); |
|||
int1 int = arg1; |
|||
int2 int = arg2; |
|||
sum int = int1 + int2; |
|||
SysLib.writeStdout("sum1: " + sum); |
|||
onException(exception AnyException) |
|||
SysLib.writeStdout("No valid input. Provide 2 integer numbers as arguments to the program."); |
|||
end |
|||
end |
|||
end |
|||
</lang> |
|||
=={{header|Excel}}== |
=={{header|Excel}}== |
||
Line 2,417: | Line 2,419: | ||
>> 102 : num |
>> 102 : num |
||
</pre> |
</pre> |
||
=={{header|Hy}}== |
|||
<lang hy>(print (sum (map int (.split (input)))))</lang> |
|||
Alternatively, with the "threading tail" macro: |
|||
<lang hy>(->> (input) (.split) (map int) (sum) (print))</lang> |
|||
=={{header|Huginn}}== |
=={{header|Huginn}}== |
||
Line 2,440: | Line 2,437: | ||
); |
); |
||
}</lang> |
}</lang> |
||
=={{header|Hy}}== |
|||
<lang hy>(print (sum (map int (.split (input)))))</lang> |
|||
Alternatively, with the "threading tail" macro: |
|||
<lang hy>(->> (input) (.split) (map int) (sum) (print))</lang> |
|||
=={{header|i}}== |
=={{header|i}}== |
||
Line 2,704: | Line 2,706: | ||
5 |
5 |
||
</lang> |
</lang> |
||
=={{header|Kite}}== |
|||
<lang Kite>#!/usr/bin/kite |
|||
import "System.file"; |
|||
in = System.file.stdin; |
|||
line = in|readline; |
|||
while(not (line is null)) [ |
|||
arry = line|split(" "); |
|||
result = (arry[0])|int + (arry[1])|int; |
|||
result|print; |
|||
line = in|readline; |
|||
];</lang> |
|||
{{Out}} |
|||
<pre> |
|||
$ kite a_plus_b.kt <<EOF |
|||
5 6 |
|||
EOF |
|||
11 |
|||
$</pre> |
|||
=={{header|Klong}}== |
=={{header|Klong}}== |
||
Line 2,762: | Line 2,786: | ||
(>> std::cin a b) |
(>> std::cin a b) |
||
(prn (+ a b)))</lang> |
(prn (+ a b)))</lang> |
||
=={{header|Lasso}}== |
|||
<lang lb>[a + b]</lang> |
|||
=={{header|Lang5}}== |
=={{header|Lang5}}== |
||
Line 2,770: | Line 2,791: | ||
read " " split expand drop + .</lang> |
read " " split expand drop + .</lang> |
||
=={{header|Lasso}}== |
|||
<lang lb>[a + b]</lang> |
|||
=={{header|LIL}}== |
=={{header|LIL}}== |
||
Line 2,828: | Line 2,852: | ||
<lang Lua>a,b = io.read("*number", "*number") |
<lang Lua>a,b = io.read("*number", "*number") |
||
print(a+b)</lang> |
print(a+b)</lang> |
||
=={{header|Kite}}== |
|||
<lang Kite>#!/usr/bin/kite |
|||
import "System.file"; |
|||
in = System.file.stdin; |
|||
line = in|readline; |
|||
while(not (line is null)) [ |
|||
arry = line|split(" "); |
|||
result = (arry[0])|int + (arry[1])|int; |
|||
result|print; |
|||
line = in|readline; |
|||
];</lang> |
|||
{{Out}} |
|||
<pre> |
|||
$ kite a_plus_b.kt <<EOF |
|||
5 6 |
|||
EOF |
|||
11 |
|||
$</pre> |
|||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
Line 2,902: | Line 2,904: | ||
endfm |
endfm |
||
</lang> |
|||
=={{header|Maxima}}== |
|||
<lang>in_stream: openr("/dev/stdin"); |
|||
unless (line: readline(in_stream), line=false) do ( |
|||
q: map('parse_string, split(line, " ")), |
|||
print(q[1]+q[2]) |
|||
); |
|||
close(in_stream); |
|||
</lang> |
</lang> |
||
Line 2,925: | Line 2,936: | ||
true |
true |
||
).</lang> |
).</lang> |
||
=={{header|Maxima}}== |
|||
<lang>in_stream: openr("/dev/stdin"); |
|||
unless (line: readline(in_stream), line=false) do ( |
|||
q: map('parse_string, split(line, " ")), |
|||
print(q[1]+q[2]) |
|||
); |
|||
close(in_stream); |
|||
</lang> |
|||
=={{header|min}}== |
=={{header|min}}== |
||
Line 2,954: | Line 2,956: | ||
{{out}} |
{{out}} |
||
<pre>5</pre> |
<pre>5</pre> |
||
=={{header|mIRC Scripting Language}}== |
=={{header|mIRC Scripting Language}}== |
||
Line 3,198: | Line 3,199: | ||
return ""</lang> |
return ""</lang> |
||
=={{header|Objeck}}== |
|||
<lang objeck>bundle Default { |
|||
class Vander { |
|||
function : Main(args : String[]) ~ Nil { |
|||
values := IO.Console->ReadString()->Split(" "); |
|||
if(values->Size() = 2) { |
|||
(values[0]->Trim()->ToInt() + values[1]->Trim()->ToInt())->PrintLine(); |
|||
}; |
|||
} |
|||
} |
|||
}</lang> |
|||
=={{header|Oberon-2}}== |
=={{header|Oberon-2}}== |
||
Line 3,229: | Line 3,218: | ||
46 |
46 |
||
</pre> |
</pre> |
||
=={{header|Objeck}}== |
|||
<lang objeck>bundle Default { |
|||
class Vander { |
|||
function : Main(args : String[]) ~ Nil { |
|||
values := IO.Console->ReadString()->Split(" "); |
|||
if(values->Size() = 2) { |
|||
(values[0]->Trim()->ToInt() + values[1]->Trim()->ToInt())->PrintLine(); |
|||
}; |
|||
} |
|||
} |
|||
}</lang> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
Line 3,460: | Line 3,461: | ||
=== using the List::Util module === |
=== using the List::Util module === |
||
<lang Perl>say sum split /\s+/, scalar <STDIN>;</lang> |
<lang Perl>say sum split /\s+/, scalar <STDIN>;</lang> |
||
=={{header|Perl 6}}== |
|||
{{works with|rakudo|2015.12}} |
|||
Short version with very little "line noise": |
|||
<lang perl6>get.words.sum.say;</lang> |
|||
Reduction operator <code>[+]</code>, and <code>say</code> as a function: |
|||
<lang perl6>say [+] get.words;</lang> |
|||
Long version: |
|||
<lang perl6>my ($a, $b) = $*IN.get.split(" "); |
|||
say $a + $b;</lang> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 3,520: | Line 3,510: | ||
<lang pli>get (a, b); |
<lang pli>get (a, b); |
||
put (a+b);</lang> |
put (a+b);</lang> |
||
=={{header|Pony}}== |
=={{header|Pony}}== |
||
<lang pony> |
<lang pony> |
||
Line 3,774: | Line 3,765: | ||
(displayln (+ a b)) |
(displayln (+ a b)) |
||
</lang> |
</lang> |
||
=={{header|Raku}}== |
|||
(formerly Perl 6) |
|||
{{works with|rakudo|2015.12}} |
|||
Short version with very little "line noise": |
|||
<lang perl6>get.words.sum.say;</lang> |
|||
Reduction operator <code>[+]</code>, and <code>say</code> as a function: |
|||
<lang perl6>say [+] get.words;</lang> |
|||
Long version: |
|||
<lang perl6>my ($a, $b) = $*IN.get.split(" "); |
|||
say $a + $b;</lang> |
|||
=={{header|REBOL}}== |
=={{header|REBOL}}== |
||
Line 3,902: | Line 3,905: | ||
<lang runbasic>input, x$ |
<lang runbasic>input, x$ |
||
print val(word$(x$,1)) + val(word$(x$,2))</lang> |
print val(word$(x$,1)) + val(word$(x$,2))</lang> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Line 4,036: | Line 4,037: | ||
writeln(a + b); |
writeln(a + b); |
||
end func;</lang> |
end func;</lang> |
||
=={{header|Self}}== |
|||
Works with positive and negative integers, and also more than two integers. |
|||
<lang self>((stdin readLine splitOn: ' ') mapBy: [|:e| e asInteger]) sum printLine.</lang> |
|||
=={{header|SenseTalk}}== |
=={{header|SenseTalk}}== |
||
Line 4,067: | Line 4,073: | ||
<lang setl>read(A, B); |
<lang setl>read(A, B); |
||
print(A + B);</lang> |
print(A + B);</lang> |
||
=={{header|Self}}== |
|||
Works with positive and negative integers, and also more than two integers. |
|||
<lang self>((stdin readLine splitOn: ' ') mapBy: [|:e| e asInteger]) sum printLine.</lang> |
|||
=={{header|Shiny}}== |
=={{header|Shiny}}== |
||
Line 4,088: | Line 4,089: | ||
<lang ruby>var (a, b) = read(String).words.map{.to_i}... |
<lang ruby>var (a, b) = read(String).words.map{.to_i}... |
||
say a+b</lang> |
say a+b</lang> |
||
=={{header|Simula}}== |
=={{header|Simula}}== |
||
<lang simula>BEGIN |
<lang simula>BEGIN |
||
Line 4,097: | Line 4,099: | ||
END. |
END. |
||
</lang> |
</lang> |
||
=={{header|SmileBASIC}}== |
|||
<lang smilebasic>INPUT A |
|||
INPUT B |
|||
PRINT A+B |
|||
</lang> |
|||
=={{header|SNOBOL4}}== |
|||
Simple-minded solution (literally "two somethings separated by space") |
|||
<lang snobol> input break(" ") . a " " rem . b |
|||
output = a + b |
|||
end</lang> |
|||
"Integer aware" solution: |
|||
<lang snobol> nums = "0123456789" |
|||
input span(nums) . a break(nums) span(nums) . b |
|||
output = a + b |
|||
end</lang> |
|||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
Line 4,188: | Line 4,173: | ||
<b>NOTE:</b> smart BASIC will intelligently interpret the contents of a string as a numeric value if necessary. Other versions of BASIC would require the values stored in a string to be converted to numeric values before calculation. |
<b>NOTE:</b> smart BASIC will intelligently interpret the contents of a string as a numeric value if necessary. Other versions of BASIC would require the values stored in a string to be converted to numeric values before calculation. |
||
=={{header|SmileBASIC}}== |
|||
<lang smilebasic>INPUT A |
|||
INPUT B |
|||
PRINT A+B |
|||
</lang> |
|||
=={{header|SNOBOL4}}== |
|||
Simple-minded solution (literally "two somethings separated by space") |
|||
<lang snobol> input break(" ") . a " " rem . b |
|||
output = a + b |
|||
end</lang> |
|||
"Integer aware" solution: |
|||
<lang snobol> nums = "0123456789" |
|||
input span(nums) . a break(nums) span(nums) . b |
|||
output = a + b |
|||
end</lang> |
|||
=={{header|SPAD}}== |
=={{header|SPAD}}== |
||
Line 4,868: | Line 4,870: | ||
</pre> |
</pre> |
||
This actually works for any number of integers |
This actually works for any number of integers |
||
=={{header|zonnon}}== |
|||
<lang zonnon> |
|||
module ABProblem; |
|||
var |
|||
a,b: integer; |
|||
begin |
|||
read(a,b); |
|||
writeln(a+b) |
|||
end ABProblem. |
|||
</lang> |
|||
<pre> |
|||
1 2 |
|||
3 |
|||
</pre> |
|||
=={{header|ZX Spectrum Basic}}== |
=={{header|ZX Spectrum Basic}}== |
||
Line 4,898: | Line 4,915: | ||
3.14 2^3 |
3.14 2^3 |
||
3.14 + 8 = 11.14 |
3.14 + 8 = 11.14 |
||
</pre> |
|||
=={{header|zonnon}}== |
|||
<lang zonnon> |
|||
module ABProblem; |
|||
var |
|||
a,b: integer; |
|||
begin |
|||
read(a,b); |
|||
writeln(a+b) |
|||
end ABProblem. |
|||
</lang> |
|||
<pre> |
|||
1 2 |
|||
3 |
|||
</pre> |
</pre> |