| Bytes | Lang | Time | Link |
|---|---|---|---|
| 029 | AWK | 250909T155652Z | xrs |
| 004 | Thunno 2 S | 230527T162844Z | The Thon |
| 038 | JavaScript V8 | 230520T214109Z | naffetS |
| 013 | GolfScript | 200118T012204Z | user8505 |
| 076 | Batch | 160329T204509Z | Neil |
| 045 | Octave | 160329T173817Z | Stewie G |
| 008 | Pylongolf2 | 160331T212920Z | user4701 |
| 008 | Japt | 160330T063214Z | Dennis |
| 062 | Lua | 160330T092325Z | Katenkyo |
| 4100 | J | 160329T184141Z | Leaky Nu |
| 005 | GS2 | 160329T230354Z | Dennis |
| 005 | Jelly | 160329T162954Z | a spaghe |
| 010 | Pyke | 160329T161533Z | Blue |
| 022 | R | 160329T181549Z | MickyT |
| 048 | Haskell | 160329T170048Z | nimi |
| 006 | MATL | 160329T161212Z | Luis Men |
| 009 | Pyth | 160329T161759Z | Blue |
| 010 | Pyth | 160329T161403Z | Denker |
| 065 | C | 160329T165136Z | mIllIbyt |
| 054 | Python 3 | 160329T161353Z | Calculat |
| 052 | Python 3 | 160329T163511Z | shooqie |
| 005 | 05AB1E | 160329T163253Z | Adnan |
| 010 | CJam | 160329T162719Z | Martin E |
| 009 | Minkolang 0.15 | 160329T161939Z | El'e |
Thunno 2 S, 4 bytes
sON²
With normal I/O it would be 1 byte (with S flag):
²
Explanation
sON² # Implicit input
s # Discard the first input
O # Split the second input on spaces
N # Convert each string to a number
² # Square each number
# Implicit output of the sum
GolfScript, 13 bytes
Input is extremely easy for GolfScript.
~](;{.*}%{+}*
Explanation
~ # Take & Evaluate the input
] # Wrap the whole input into a list
(; # Remove the first item
{.*}% # Map with squaring
{+}* # Reduce by summation
Batch, 76 bytes
@set/px=
@set/px=
@set t=0
@for %%n in (%x%)do set/at+=%%n*%%n
@echo %t%
Octave, 45 bytes
Octave is not exactly designed for accepting random input formats. For instance, input over multiple lines is impossible. Also, numbers can't be entered as a list unless you have brackets. For that reason, the input must be taken as a string.
input('');disp((x=str2num(input('','s')))*x')
input('') % Take the first input line and discard
input('','s') % Take the second input as a string
x=str2num(input('','s')) % Convert the string to a list of numbers, x
(x=str2num(input('','s')))*x' % Multiply x by x transposed
% This is equivalent to sum(x.^2) but shorter
disp((x=str2num(input('','s')))*x') % Display the result
Call it like this:
input('');disp((x=str2num(input('','s')))*x')
5
1 2 5 7 8
143
Pylongolf2, 8 bytes
c| n²+~
c - read the input
| - split by space (note the 1 space after |)
n - convert all of that in the list to numbers
² - Square everything in the list
+ - Sum everything in the list
~ - Print it
Japt, 8 bytes
Ns1 mp x
Try it in the Japt Interpreter.
How it works
The code is parsed as
N.s(1).m(p).x()
Nis a variable; it contains the parsed input.s(1)discards the first array element.m(p)mapsp(square) over the remaining array.x()computes the sum of the array of squares.
Lua, 74 62 Bytes
Edit: saved 8 bytes due to @KennyLau
It's quite straigthforward, skip the first line and iterate over the group of digits in the second.
i,x=io.read,0i()i():gsub("%d+",function(d)x=x+d*d end)print(x)
Ungolfed
x=0
i=io.read
i()
i():gsub("%d+",function(d)
x=x+d*d
end)
print(x)
J, 4 bytes + 100
+/*:
+/*:1 2 5 7 8
143
A +100 punishment in the byte-count to myself for not having standard input.
GS2, 5 bytes
W",Φd
How it works
W Find all numbers in the input; push a list.
" Discard the first number.
, Square.
Φ Map the last instruction over the list of numbers.
d Compute the sum of all squares.
Jelly, 5 bytes
ṣ⁶V²S
Input format is rather annoying....
Explanation
ṣ⁶V²S
ṣ⁶ split by space
V map eval over the resulting list -- the newline in the first element causes the first line to be treated as a separate link and ignored
² map square over the list
S sum
Pyke, 10 bytes
;\ cFE2^)s
Takes input as requested
Try it here (Yay setup a try-it page!)
Or 5 bytes if allowed a list of ints:
2Rm^s
Or noncompeting (add squared node), 3 bytes
mXs
R, 22 bytes
Nothing very flash, handles the input as specified
cat(sum(scan()[-1]^2))
Test run
> cat(sum(scan()[-1]^2))
1: 5
2: 1 2 5 7 8
7:
Read 6 items
143
>
Haskell, 48 bytes
main=interact$show.sum.map((^2).read).tail.words
How it works:
interact read whole input, pass it to a function and
print it's return value. The function is:
words split at whitespace into words
tail drop first element (the number on line #1)
map( ) convert each word
read to integers
(^2) and square
sum sum all values
show convert back to string
MATL, 6 bytes
xjU2^s
x % take first input and throw it away
j % take second input as a string
U % convert to array with those numbers
2^ % element-wise square
s % sum of array
Pyth, 10 bytes
sm^sd2ce.z
Takes input in the exact same format as specified in the challenge.
Explanation
sm^sd2ce.z # .z = input lines
e.z # only take the last line
c # split on spaces
m # map each number d
sd # convert to integer
^ 2 # square
s # sum all squares
Alterntive solutions with more generous input formats
8 bytes if I may omit the number count:
sm^sd2cz
4 bytes if I may take the input as list of integers:
s^R2
C,65 bytes
j,k;main(i){for(;scanf("%d",&i)+1;j++&&(k+=i*i));printf("%d",k);}
Python 3, 54 bytes
-[] thanks to shooqie
print(sum(int(i)**2for i in input(input()).split()))
Takes input as specified in the first version of the question.
So to answer your question: Not a lot.
Python 3, 52
i=input;print(sum(int(d)**2for d in i(i()).split()))
05AB1E, 5 bytes
Code:
²ð¡nO
Explanation:
² # Take the second input, the first input is ignored
ð¡ # Split on spaces
n # Square each element
O # Take the sum and implicitly output it
Uses CP-1252 encoding.
CJam, 10 bytes
l;l~]2f#1b
Explanation
l; e# Read first line and discard.
l~ e# Read second line and evaluate, dumping all integers on the stack.
] e# Wrap them in an array.
2f# e# Square each.
1b e# Sum.
Minkolang 0.15, 9 bytes
n[n2;+]N.
Explanation
n Take number from input
[ ] Pop top of stack and repeat that many times
n Take number from input
2; Square it
+ Add to top of stack
N. Output as number and stop.