task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Python
Python
#!/usr/bin/env python   from collections import Counter   def decompose_sum(s): return [(a,s-a) for a in range(2,int(s/2+1))]   # Generate all possible pairs all_pairs = set((a,b) for a in range(2,100) for b in range(a+1,100) if a+b<100)   # Fact 1 --> Select pairs for which all sum decompositions have non-unique p...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#XLISP
XLISP
(DEFUN CONVERT-TEMPERATURE () (SETQ *FLONUM-FORMAT* "%.2f") (DISPLAY "Enter a temperature in Kelvin.") (NEWLINE) (DISPLAY "> ") (DEFINE K (READ)) (DISPLAY `(K = ,K)) (NEWLINE) (DISPLAY `(C = ,(- K 273.15))) (NEWLINE) (DISPLAY `(F = ,(- (* K 1.8) 459.67))) (NEWLINE) (DISPL...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#XPL0
XPL0
include c:\cxpl\codes; real K, C, F, R; [ChOut(0, ^K); K:= RlIn(0); C:= K - 273.15; ChOut(0, ^C); RlOut(0, C); CrLf(0); F:= 1.8*C + 32.0; ChOut(0, ^F); RlOut(0, F); CrLf(0); R:= F + 459.67; ChOut(0, ^R); RlOut(0, R); CrLf(0); ]
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#REXX
REXX
/*REXX program to add a (either metric or "binary" metric) suffix to a decimal number.*/ @.= /*default value for the stemmed array. */ parse arg @.1 /*obtain optional arguments from the CL*/ if @.1=='' then do; @.1= ' 87,654,321 ...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#ALGOL_W
ALGOL W
begin % compute the sum of 1/k^2 for k = 1..1000 % integer k;  % computes the sum of a series from lo to hi using Jensen's Device % real procedure sum ( integer %name% k; integer value lo, hi; real procedure term ); begin real temp; temp := 0; k := lo; while k <= hi do be...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#TI-89_BASIC
TI-89 BASIC
■ getTime() {13 28 55} ■ getDate() {2009 8 13}
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#True_BASIC
True BASIC
PRINT DATE$ ! returns SYSTEM date in format: “YYYYMMDD”. ! Here YYYY IS the year, MM IS the month number, AND DD IS the day number.   PRINT TIME$ ! returns SYSTEM time in format: “HH:MM:SS”. END
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#11l
11l
-V NUMBER_OF_DIGITS = 9 THREE_POW_4 = 3 * 3 * 3 * 3 NUMBER_OF_EXPRESSIONS = 2 * THREE_POW_4 * THREE_POW_4   T.enum Op ADD SUB JOIN   T Expression code = [Op.ADD] * :NUMBER_OF_DIGITS   F inc() L(i) 0 .< .code.len .code[i] = Op((Int(.code[i]) + 1) % 3) I .code[i] != ADD ...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#AppleScript
AppleScript
----------------- SUM MULTIPLES OF 3 AND 5 -----------------   -- sum35 :: Int -> Int on sum35(n) tell sumMults(n) |λ|(3) + |λ|(5) - |λ|(15) end tell end sum35       -- sumMults :: Int -> Int -> Int on sumMults(n) -- Area under straight line -- between first multiple and last. script ...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#ArnoldC
ArnoldC
LISTEN TO ME VERY CAREFULLY sumDigits I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE n I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE base GIVE THESE PEOPLE AIR HEY CHRISTMAS TREE sum YOU SET US UP @I LIED STICK AROUND n HEY CHRISTMAS TREE digit YOU SET US UP @I LIED GET TO THE CHOPPER digit HERE IS MY INVITATI...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#ALGOL_W
ALGOL W
begin  % procedure to sum the elements of a vector. As the procedure can't find %  % the bounds of the array for itself, we pass them in lb and ub  % real procedure sumSquares ( real array vector ( * )  ; integer value lb  ; integer value ub...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Alore
Alore
def sum_squares(a) var sum = 0 for i in a sum = sum + i**2 end return sum end   WriteLn(sum_squares([3,1,4,1,5,9])) end
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Action.21
Action!
DEFINE LAST="6"   PROC Main() INT ARRAY data=[1 2 3 4 5 6 7] BYTE i INT a,res   res=0 FOR i=0 TO LAST DO a=data(i) PrintI(a) IF i=LAST THEN Put('=) ELSE Put('+) FI res==+a OD PrintIE(res)   res=1 FOR i=0 TO LAST DO a=data(i) PrintI(a) IF i=LAST THEN ...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Racket
Racket
#lang racket (define-syntax-rule (define/mem (name args ...) body ...) (begin (define cache (make-hash)) (define (name args ...) (hash-ref! cache (list args ...) (lambda () body ...)))))   (define (sum p) (+ (first p) (second p))) (define (mul p) (* (first p) (second p)))   (define (sum= p s) (filter (l...
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#zkl
zkl
K:=ask(0,"Kelvin: ").toFloat(); println("K %.2f".fmt(K)); println("F %.2f".fmt(K*1.8 - 459.67)); println("C %.2f".fmt(K - 273.15)); println("R %.2f".fmt(K*1.8));
http://rosettacode.org/wiki/Temperature_conversion
Temperature conversion
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. 0 degrees Celsius corresponds to 273.15 kelvin. 0 kelvin is absolute z...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 REM Translation of traditional basic version 20 INPUT "Kelvin Degrees? ";k 30 IF k <= 0 THEN STOP: REM A value of zero or less will end program 40 LET c = k - 273.15 50 LET f = k * 1.8 - 459.67 60 LET r = k * 1.8 70 PRINT k; " Kelvin is equivalent to" 80 PRINT c; " Degrees Celsius" 90 PRINT f; " Degrees Fahrenheit" ...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#VBA
VBA
Private Function suffize(number As String, Optional sfractiondigits As String, Optional base As String) As String Dim suffix As String, parts() As String, exponent As String Dim fractiondigits As Integer, nsuffix As Integer, flag As Boolean flag = False fractiondigits = Val(sfractiondigits) suffixes...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#APL
APL
+/÷2*⍨⍳1000 1.64393
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT time=time() PRINT time
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#UNIX_Shell
UNIX Shell
date # Thu Dec 3 15:38:06 PST 2009   date +%s # 1259883518, seconds since the epoch, like C stdlib time(0)
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#Ada
Ada
package Sum_To is   generic with procedure Callback(Str: String; Int: Integer); procedure Eval;   generic Number: Integer; with function Print_If(Sum, Number: Integer) return Boolean; procedure Print(S: String; Sum: Integer);   end Sum_To;
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Arturo
Arturo
sumMul35: function [n][ sum select 1..n-1 [x][or? 0=x%3 0=x%5] ]   print sumMul35 1000
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Arturo
Arturo
sumDigits: function [n base][ result: 0 while [n>0][ result: result + n%base n: n/base ] return result ]   print sumDigits 1 10 print sumDigits 12345 10 print sumDigits 123045 10 print sumDigits from.hex "0xfe" 16 print sumDigits from.hex "0xf0e" 16
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#APL
APL
square_sum←{+/⍵*2} square_sum 1 2 3 4 5 55 square_sum ⍬ ⍝The empty vector 0
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#AppleScript
AppleScript
------ TWO APPROACHES – SUM OVER MAP, AND DIRECT FOLD ----   -- sumOfSquares :: Num a => [a] -> a on sumOfSquares(xs) script squared on |λ|(x) x ^ 2 end |λ| end script   sum(map(squared, xs)) end sumOfSquares     -- sumOfSquares2 :: Num a => [a] -> a on sumOfSquares2(xs) scri...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#ActionScript
ActionScript
package { import flash.display.Sprite;   public class SumAndProduct extends Sprite { public function SumAndProduct() { var arr:Array = [1, 2, 3, 4, 5]; var sum:int = 0; var prod:int = 1;   for (var i:int = 0; i < arr.length; i++) { sum += arr[i]; prod *= arr[i]; }   trace("Sum: " + s...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Raku
Raku
sub grep-unique (&by, @list) { @list.classify(&by).values.grep(* == 1).map(*[0]) } sub sums ($n) { ($_, $n - $_ for 2 .. $n div 2) } sub sum ([$x, $y]) { $x + $y } sub product ([$x, $y]) { $x * $y }   my @all-pairs = (|($_ X $_+1 .. 98) for 2..97);   # Fact 1: my %p-unique := Set.new: map...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#Wren
Wren
import "/big" for BigRat import "/fmt" for Fmt   var suffixes = " KMGTPEZYXWVU" var googol = BigRat.fromDecimal("1e100")   var suffize = Fn.new { |arg| var fields = arg.split(" ").where { |s| s != "" }.toList if (fields.isEmpty) fields.add("0") var a = fields[0] var places var base var frac = "...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#AppleScript
AppleScript
----------------------- SUM OF SERIES ----------------------   -- seriesSum :: Num a => (a -> a) -> [a] -> a on seriesSum(f, xs) script go property mf : |λ| of mReturn(f) on |λ|(a, x) a + mf(x) end |λ| end script   foldl(go, 0, xs) end seriesSum     ----------------------...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Ursa
Ursa
# outputs time in milliseconds import "time" out (time.getcurrent) endl console
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Ursala
Ursala
#import cli   #cast %s   main = now 0
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#Aime
Aime
integer b, i, j, k, l, p, s, z; index r, w;   i = 0; while (i < 512) { b = i.bcount; j = 0; while (j < 1 << b) { data e;   j += 1;   k = s = p = 0; l = j; z = 1; while (k < 9) { if (i & 1 << k) { e.append("-+"[l & 1]); ...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#AutoHotkey
AutoHotkey
n := 1000   msgbox % "Sum is " . Sum3_5(n) . " for n = " . n msgbox % "Sum is " . Sum3_5_b(n) . " for n = " . n   ;Standard simple Implementation. Sum3_5(n) { sum := 0 loop % n-1 { if (!Mod(a_index,3) || !Mod(a_index,5)) sum:=sum+A_index } return sum }   ;Translated from the C++ version. Sum3_5_b( i ) { sum ...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#ATS
ATS
  (* ****** ****** *) // // How to compile: // patscc -DATS_MEMALLOC_LIBC -o SumDigits SumDigits.dats // (* ****** ****** *) // #include "share/atspre_staload.hats" // (* ****** ****** *)   extern fun{a:t@ype} SumDigits(n: a, base: int): a   implement {a}(*tmp*) SumDigits(n, base) = let // val base = gnumber_int(base) ...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Arturo
Arturo
arr: 1..10   print sum map arr [x][x^2]
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Astro
Astro
sum([1, 2, 3, 4]²)
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Ada
Ada
type Int_Array is array(Integer range <>) of Integer;   array : Int_Array := (1,2,3,4,5,6,7,8,9,10); Sum : Integer := 0; for I in array'range loop Sum := Sum + array(I); end loop;
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#REXX
REXX
debug=0 If debug Then Do oid='sppn.txt'; 'erase' oid End Call time 'R' all_pairs='' cnt.=0 i=0 /* first take all possible pairs 2<=x<y with x+y<=100 */ /* and compute the respective sums and products */ /* count the number of times a sum or product occurs */ Do x=2 To 98 Do y=x+1 To 100-x x=right(x,2,0...
http://rosettacode.org/wiki/Suffixation_of_decimal_numbers
Suffixation of decimal numbers
Suffixation:   a letter or a group of letters added to the end of a word to change its meaning.       ─────   or, as used herein   ───── Suffixation:   the addition of a metric or "binary" metric suffix to a number, with/without rounding. Task Write a function(s) to append (if possible)   a metric   or   a "binar...
#zkl
zkl
var [const] BI=Import.lib("zklBigNum"); // GMP var metric, binary, googol=BI("1e100"); metric,binary = metricBin();   // suffix: "2" (binary), "10" (metric) // For this task, we'll assume BF numbers and treat everything as a big int fcn sufficate(numStr, fracDigits=",", suffix="10"){ var [const] numRE=RegExp(...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Arturo
Arturo
series: map 1..1000 => [1.0/&^2] print [sum series]
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Vala
Vala
  var now = new DateTime.now_local(); string now_string = now.to_string();
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#VBA
VBA
Debug.Print Now()
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#ALGOL_68
ALGOL 68
BEGIN # find the numbers the string 123456789 ( with "+/-" optionally inserted # # before each digit ) can generate #   # experimentation shows that the largest hundred numbers that can be # # generated are are greater than or equal to 56795 ...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#AWK
AWK
#!/usr/bin/awk -f { n = $1-1; print sum(n,3)+sum(n,5)-sum(n,15); } function sum(n,d) { m = int(n/d); return (d*m*(m+1)/2); }
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#AutoHotkey
AutoHotkey
MsgBox % sprintf("%d %d %d %d %d`n" ,SumDigits(1, 10) ,SumDigits(12345, 10) ,SumDigits(123045, 10) ,SumDigits(0xfe, 16) ,SumDigits(0xf0e, 16) )   SumDigits(n,base) { sum := 0 while (n) { sum += Mod(n,base) n /= base } return sum }   sprintf(s,fmt*) { for each, f in fmt StringReplace,s,s,`%d, % f retur...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Asymptote
Asymptote
int suma; int[] a={1, 2, 3, 4, 5, 6};   for(var i : a) suma = suma + a[i] ^ 2;   write("The sum of squares is: ", suma);
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#AutoHotkey
AutoHotkey
list = 3 1 4 1 5 9 Loop, Parse, list, %A_Space% sum += A_LoopField**2 MsgBox,% sum
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Aime
Aime
void compute(integer &s, integer &p, list l) { integer v;   s = 0; p = 1; for (, v in l) { s += v; p *= v; } }   integer main(void) { integer sum, product;   compute(sum, product, list(2, 3, 5, 7, 11, 13, 17, 19));   o_form("~\n~\n", sum, product);   return 0; }
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#ALGOL_68
ALGOL 68
main:( INT default upb := 3; MODE INTARRAY = [default upb]INT;   INTARRAY array = (1,2,3,4,5,6,7,8,9,10); INT sum := 0; FOR i FROM LWB array TO UPB array DO sum +:= array[i] OD;   # Define the product function # PROC int product = (INTARRAY item)INT: ( INT prod :=1; FOR i FROM LWB item TO...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Ruby
Ruby
def add(x,y) x + y end def mul(x,y) x * y end   def sumEq(s,p) s.select{|q| add(*p) == add(*q)} end def mulEq(s,p) s.select{|q| mul(*p) == mul(*q)} end   s1 = (a = *2...100).product(a).select{|x,y| x<y && x+y<100} s2 = s1.select{|p| sumEq(s1,p).all?{|q| mulEq(s1,q).size != 1} } s3 = s2.select{|p| (mulEq(s1,p) & s2).siz...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#AutoHotkey
AutoHotkey
SetFormat, FloatFast, 0.15 While A_Index <= 1000 sum += 1/A_Index**2 MsgBox,% sum ;1.643934566681554
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#VBScript
VBScript
WScript.Echo Now
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Vlang
Vlang
import time   fn main() { t := time.Now() println(t) // default format YYYY-MM-DD HH:MM:SS println(t.custom_format("ddd MMM d HH:mm:ss YYYY")) // some custom format }
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#AppleScript
AppleScript
use framework "Foundation" -- for basic NSArray sort   property pSigns : {1, 0, -1} --> ( + | unsigned | - ) property plst100 : {"Sums to 100:", ""} property plstSums : {} property plstSumsSorted : missing value property plstSumGroups : missing value   -- data Sign :: [ 1 | 0 | -1 ] = ( Plus | Unsigned | Minus ) -- asS...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#BASIC
BASIC
Declare function mulsum35(n as integer) as integer Function mulsum35(n as integer) as integer Dim s as integer For i as integer = 1 to n - 1 If (i mod 3 = 0) or (i mod 5 = 0) then s += i End if Next i Return s End Function Print mulsum35(1000) Sleep End
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#AWK
AWK
#!/usr/bin/awk -f   BEGIN { print sumDigits("1") print sumDigits("12") print sumDigits("fe") print sumDigits("f0e") }   function sumDigits(num, nDigs, digits, sum, d, dig, val, sum) { nDigs = split(num, digits, "") sum = 0 for (d = 1; d <= nDigs; d++) { dig = digits[d] val...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#AWK
AWK
$ awk '{s=0;for(i=1;i<=NF;i++)s+=$i*$i;print s}' 3 1 4 1 5 9 133   0
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#BASIC
BASIC
sum = 0 FOR I = LBOUND(a) TO UBOUND(a) sum = sum + a(I) ^ 2 NEXT I PRINT "The sum of squares is: " + sum
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#ALGOL_W
ALGOL W
begin    % computes the sum and product of intArray  %  % the results are returned in sum and product  %  % the bounds of the array must be specified in lb and ub  % procedure sumAndProduct( integer array intArray ( * ) ...
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Scala
Scala
object ImpossiblePuzzle extends App { type XY = (Int, Int) val step0 = for { x <- 1 to 100 y <- 1 to 100 if 1 < x && x < y && x + y < 100 } yield (x, y)   def sum(xy: XY) = xy._1 + xy._2 def prod(xy: XY) = xy._1 * xy._2 def sumEq(xy: XY) = step0 filter { sum(_) == sum(xy) } def prodEq(xy: XY) ...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#AWK
AWK
$ awk 'BEGIN{for(i=1;i<=1000;i++)s+=1/(i*i);print s}' 1.64393
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Wren
Wren
import "os" for Process import "/date" for Date   var args = Process.arguments if (args.count != 1) Fiber.abort("Please pass the current time in hh:mm:ss format.") var startTime = Date.parse(args[0], Date.isoTime) for (i in 0..1e8) {} // do something which takes a bit of time var now = startTime.addMillisecs((System.cl...
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#XPL0
XPL0
include c:\cxpl\codes; \include intrinsic 'code' declarations   proc NumOut(N); \Output a 2-digit number, including leading zero int N; [if N <= 9 then ChOut(0, ^0); IntOut(0, N); ]; \NumOut   int Reg; [Reg:= GetReg; \get address of array with copy of CPU registers Reg(0):= $2...
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#AutoHotkey
AutoHotkey
output:="" for k, v in (sum2num(100)) output .= k "`n" MsgBox, 262144, , % output   mx := [] loop 123456789{ x := sum2num(A_Index) mx[x.Count()] := mx[x.Count()] ? mx[x.Count()] ", " A_Index : A_Index } MsgBox, 262144, , % mx[mx.MaxIndex()] " has " mx.MaxIndex() " solutions"   loop { if !sum2num(A_Index...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#bc
bc
define t(n, f) { auto m   m = (n - 1) / f return(f * m * (m + 1) / 2) }   define s(l) { return(t(l, 3) + t(l, 5) - t(l, 15)) }   s(1000) s(10 ^ 20)
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#BASIC
BASIC
FUNCTION sumDigits(num AS STRING, bas AS LONG) AS LONG 'can handle up to base 36 DIM outp AS LONG DIM validNums AS STRING, tmp AS LONG, x AS LONG, lennum AS LONG, L0 AS LONG 'ensure num contains only valid characters validNums = LEFT$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", bas) lennum = LEN(num...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#bc
bc
define s(a[], n) { auto i, s   for (i = 0; i < n; i++) { s += a[i] * a[i] }   return(s) }
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#BCPL
BCPL
get "libhdr"   let sumsquares(v, len) = len=0 -> 0,  !v * !v + sumsquares(v+1, len-1)   let start() be $( let vector = table 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 writef("%N*N", sumsquares(vector, 10)) $)
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#APL
APL
sum ← +/ prod ← ×/   list ← 1 2 3 4 5   sum list 15   prod list 120
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#AppleScript
AppleScript
set array to {1, 2, 3, 4, 5} set sum to 0 set product to 1 repeat with i in array set sum to sum + i set product to product * i end repeat
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Scheme
Scheme
  (import (scheme base) (scheme cxr) (scheme write) (srfi 1))   ;; utility method to find unique sum/product in given list (define (unique-items lst key) (let ((all-items (map key lst))) (filter (lambda (i) (= 1 (count (lambda (p) (= p (key i))) all-item...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#BASIC
BASIC
FUNCTION s(x%) s = 1 / x ^ 2 END FUNCTION   FUNCTION sum(low%, high%) ret = 0 FOR i = low TO high ret = ret + s(i) NEXT i sum = ret END FUNCTION PRINT sum(1, 1000)
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#Yabasic
Yabasic
print time$
http://rosettacode.org/wiki/System_time
System time
Task Output the system time   (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance. Related task   Date format See also   Retr...
#zkl
zkl
Time.Clock.time //-->seconds since the epoch (C/OS defined)
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#AWK
AWK
# # RossetaCode: Sum to 100, AWK. # # Find solutions to the "sum to one hundred" puzzle.   function evaluate(code) { value = 0 number = 0 power = 1 for ( k = 9; k >= 1; k-- ) { number = power*k + number op = code % 3 if ( op == 0 ) { value = value + number ...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#BCPL
BCPL
  GET "libhdr"   LET sumdiv(n, d) = VALOF { LET m = n/d RESULTIS m*(m + 1)/2 * d }   LET sum3or5(n) = sumdiv(n, 3) + sumdiv(n, 5) - sumdiv(n, 15)   LET start() = VALOF { LET sum = 0 LET n = 1   FOR k = 1 TO 999 DO IF k MOD 3 = 0 | k MOD 5 = 0 THEN sum +:= k writef("The sum of the multipl...
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#BBC_BASIC
BBC BASIC
*FLOAT64 PRINT "Digit sum of 1 (base 10) is "; FNdigitsum(1, 10) PRINT "Digit sum of 12345 (base 10) is "; FNdigitsum(12345, 10) PRINT "Digit sum of 9876543210 (base 10) is "; FNdigitsum(9876543210, 10) PRINT "Digit sum of FE (base 16) is "; ~FNdigitsum(&FE, 16) " (base 16)" PRINT "D...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#BQN
BQN
SSq ← +´√⁼   •Show SSq 1‿2‿3‿4‿5 •Show SSq ⟨⟩
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Bracmat
Bracmat
( ( sumOfSquares = sum component . 0:?sum & whl ' ( !arg:%?component ?arg & !component^2+!sum:?sum ) & !sum ) & out$(sumOfSquares$(3 4)) & out$(sumOfSquares$(3 4 i*5)) & out$(sumOfSquares$(a b c)) );
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Arturo
Arturo
arr: 1..10   print ["Sum =" sum arr] print ["Product =" product arr]
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Asymptote
Asymptote
int[] matriz = {1,2,3,4,5}; int suma = 0, prod = 1;   for (int p : matriz) { suma += p; prod *= p; } write("Sum = ", suma); write("Product = ", prod);
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Sidef
Sidef
func grep_uniq(a, by) { a.group_by{ .(by) }.values.grep{.len == 1}.map{_[0]} } func sums (n) { 2 .. n//2 -> map {|i| [i, n-i] } }   var pairs = (2..97 -> map {|i| ([i] ~X (i+1 .. 98))... })   var p_uniq = Hash() p_uniq{grep_uniq(pairs, :prod).map { .to_s }...} = ()   var s_pairs = pairs.grep {|p| sums(p.sum).al...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#bc
bc
define f(x) { return(1 / (x * x)) }   define s(n) { auto i, s   for (i = 1; i <= n; i++) { s += f(i) }   return(s) }   scale = 20 s(1000)
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#C
C
/* * RossetaCode: Sum to 100, C99, an algorithm using ternary numbers. * * Find solutions to the "sum to one hundred" puzzle. */   #include <stdio.h> #include <stdlib.h>   /* * There are only 13122 (i.e. 2*3**8) different possible expressions, * thus we can encode them as positive integer numbers from 0 to 1312...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Befunge
Befunge
&1-:!#v_:3%#v_ >:># >+\:v >:5%#v_^ @.$_^#! < > ^
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#bc
bc
define s(n) { auto i, o, s   o = scale scale = 0   for (i = n; i > 0; i /= ibase) { s += i % ibase }   scale = o return(s) }   ibase = 10 s(1) s(1234) ibase = 16 s(FE) s(F0E)
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Brat
Brat
p 1.to(10).reduce 0 { res, n | res = res + n ^ 2 } #Prints 385
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#C
C
#include <stdio.h>   double squaredsum(double *l, int e) { int i; double sum = 0.0; for(i = 0 ; i < e ; i++) sum += l[i]*l[i]; return sum; }   int main() { double list[6] = {3.0, 1.0, 4.0, 1.0, 5.0, 9.0};   printf("%lf\n", squaredsum(list, 6)); printf("%lf\n", squaredsum(list, 0)); /* the same with...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#AutoHotkey
AutoHotkey
numbers = 1,2,3,4,5 product := 1 loop, parse, numbers, `, { sum += A_LoopField product *= A_LoopField } msgbox, sum = %sum%`nproduct = %product%
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#Wren
Wren
import "/dynamic" for Tuple import "/seq" for Lst   var P = Tuple.create("P", ["x", "y", "sum", "prod"])   var intersect = Fn.new { |l1, l2| var l3 = (l1.count < l2.count) ? l1 : l2 var l4 = (l3 == l1) ? l2 : l1 var l5 = [] for (e in l3) if (l4.contains(e)) l5.add(e) return l5 }   var candidates = [...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Beads
Beads
beads 1 program 'Sum of a series' calc main_init var k = 0 loop reps:1000 count:n k = k + 1/n^2 log to_str(k)
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#C.23
C#
using System; using System.Collections.Generic; using System.Linq;   class Program { static void Main(string[] args) { // All unique expressions that have a plus sign in front of the 1; calculated in parallel var expressionsPlus = Enumerable.Range(0, (int)Math.Pow(3, 8)).AsParallel().Select(i =>...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#BQN
BQN
Sum ← +´·(0=3⊸|⌊5⊸|)⊸/↕
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#BCPL
BCPL
get "libhdr"   let digitsum(n, base) = n=0 -> 0, n rem base + digitsum(n/base, base)   let start() be $( writef("%N*N", digitsum(1, 10)) // prints 1 writef("%N*N", digitsum(1234, 10)) // prints 10 writef("%N*N", digitsum(#1234, 8)) // also prints 10 writef("%N*N", digitsum(#XFE, 16)) //...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#C.23
C#
using System; using System.Collections.Generic; using System.Linq;   class Program { static int SumOfSquares(IEnumerable<int> list) { return list.Sum(x => x * x); } static void Main(string[] args) { Console.WriteLine(SumOfSquares(new int[] { 4, 8, 15, 16, 23, 42 })); // 2854 ...
http://rosettacode.org/wiki/Substitution_cipher
Substitution cipher
Substitution Cipher Implementation - File Encryption/Decryption Task Encrypt a input/source file by replacing every upper/lower case alphabets of the source file with another predetermined upper/lower case alphabets or symbols and save it into another output/encrypted file and then again convert that output/encrypt...
#11l
11l
V key = ‘]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs"v*N[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\C1yxJ’   F encode(s) V r = ‘’ L(c) s r ‘’= :key[c.code - 32] R r   F decode(s) V r = ‘’ L(c) s r ‘’= Char(code' :key.index(c) + 32) R r   V s = ‘The quick brown fox jumps over the lazy dog, wh...
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#AWK
AWK
$ awk 'func sum(s){split(s,a);r=0;for(i in a)r+=a[i];return r}{print sum($0)}' 1 2 3 4 5 6 7 8 9 10 55   $ awk 'func prod(s){split(s,a);r=1;for(i in a)r*=a[i];return r}{print prod($0)}' 1 2 3 4 5 6 7 8 9 10 3628800
http://rosettacode.org/wiki/Sum_and_product_puzzle
Sum and product puzzle
Task[edit] Solve the "Impossible Puzzle": X and Y are two different whole numbers greater than 1. Their sum is no greater than 100, and Y is greater than X. S and P are two mathematicians (and consequently perfect logicians); S knows the sum X+Y and P knows the product X*Y. Both S and P know all the information in th...
#zkl
zkl
mul:=Utils.Helpers.summer.fp1('*,1); //-->list.reduce('*,1), multiply list items var allPairs=[[(a,b); [2..100]; { [a+1..100] },{ a+b<100 }; ROList]]; // 2,304 pairs   sxys,pxys:=Dictionary(),Dictionary(); // hashes of allPairs sums and products: 95,1155 foreach xy in (allPairs){ sxys.appendV(xy.sum(),xy); pxys.append...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Befunge
Befunge
05558***>::"~"%00p"~"/10p"( }}2"*v v*8555$_^#!:-1+*"~"g01g00+/*:\***< <@$_,#!>#:<+*<v+*86%+55:p00<6\0/** "."\55+%68^>\55+/00g1-:#^_$
http://rosettacode.org/wiki/Sum_to_100
Sum to 100
Task Find solutions to the   sum to one hundred   puzzle. Add (insert) the mathematical operators     +   or   -     (plus or minus)   before any of the digits in the decimal numeric string   123456789   such that the resulting mathematical expression adds up to a particular sum   (in this iconic case,   ...
#C.2B.2B
C++
/* * RossetaCode: Sum to 100, C++, STL, OOP. * Works with: MSC 16.0 (MSVS2010); GCC 5.1 (use -std=c++11 or -std=c++14 etc.). * * Find solutions to the "sum to one hundred" puzzle. */ #include <iostream> #include <iomanip> #include <algorithm> #include <string> #include <set> #include <map>   using namespace std;...