text:
Sum the numbers on standard in
Consider a stream/file with one integer per line. For example:
123
5
99

Your code should output the sum of these numbers, that is 227.
The input format is strictly one integer per line. You cannot, for example, assume the input is on one line as an array of integers.
You can take input either from STDIN, in form of a filename, or a file with a name of your choice; you can choose which one. No other ways of getting input are allowed.
The input will contain at least one integer. You can assume all integers are non-negative and that their total sum is less than 232.

Is there a trailing newline?  Is that newline optional?

Hi! I downvoted this challenge because it goes against our community standards for acceptable input/output formats by having a restrictive input format.

@AdmBorkBork and I discussed this at length in the chat room. We have agreed to disagree :)

As the author of the things-to-avoid of cumbersome I/O and arbitrarily overriding defaults, I want to defend this challenge on those grounds. Here, the processing input is the meat of the challenge, not extra work that distracts from the main challenge. It's not "add numbers" with weird I/O requirements, it's "do this I/O" with adding as a step. Overruling the standard I/O is necessary  for answers not to shortcut across the main task.

@ais523 Ahem.

@Dennis: OK, I didn't think of that. Still fairly ridiculous that you have to go to those lengths, though.

Why can't function input be used?

05AB1E, 2 bytes
|O

Explanation:
|   Get input as array
 O  Sum

Try it online!

That's ridiculous :)

Does this read from standard in?

@Lembik it does.

I believe your 2 byte answer was first. You are the winner!  (Unless someone finds a 1 byte answer.)

@Lembik Or a 0 byte answer....

@SparklePony Write a compiler/interpreter that compiles anything to a solution to this problem - then the submission is a 0 byte program that compiles to a solution? Sorted :)

Bash + coreutils, 16 bytes
xargs|tr \  +|bc

Try it online!
There are two spaces after the \. This works for negative numbers as well.
Explanation:
xargs             # known trick to turn newlines into spaces, while adding a
                  #trailing newline when printing the result (needed for bc)
|tr \  +          # turn spaces into '+'s
|bc               # calculates the sum

You may wonder why tr \\n +|bc isn't better, since it turns newlines directly into '+'s. Well, that has 2 unforeseen errors:

if the input has a trailing newline, then it is converted to a trailing '+', hence there is no number after it to perform the addition
and the most weird issue is that bc requires a trailing newline after the input, but you just replaced all of the input newlines with '+'s.

I like this.  It's nice and clever.

Could you use tr \n + Instead without xargs?

@Lembik Do you mean tr \\n +|bc? If so, then please see the updated explanation. Good question.

paste -s -d+|bc is 15 bytes

@DavidConrad The use of paste is shown in another bash answer here. No harm keeping both. Thank you for the comment anyway.

Does this work if there is only one line?

@Lembik Didn't considered that case, but fortunately the script still works. xargs|tr \  + in this case does nothing, and bc receives the number and prints it back.

@seshoumara I agree. I hadn't seen that other answer yet when I commented. Cheers.

This is not bash specific, so should read "sh + POSIX utils"

@Jens I'm glad that it works on other shells as well, thanks for the info, but I'll keep bash in the title, since it is better known and since it's the system I tested on.

MATL, 2 bytes
Us

This expects the input in a text file called defin.
Gif or it didn't happen:

Or try it online! (thanks to Dennis for the set-up!)
Explanation
When a MATL program is run, if a file called defin is found (the name refers to "default input"), its contents are automatically loaded as text and pushed to the stack as a string before executing the code.
Function U evaluates the string to convert it to a column vector of numbers, and s computes the sum, which is implicitly displayed.

Japt, 2 bytes
Nx

Explanation
     Implicit: parse STDIN into array of numbers, strings, and arrays
N    Get the resulting parsed array.
 x   Sum.
     Implicit: output result of last expression

Try it online!

Perl 6, 13 bytes
say sum lines

Try it
Explanation

lines() returns a list of lines from $*IN or $*ARGFILES a “magic” command-line input handle.
sum(…) was added to Perl 6 to allow [+] List to be optimized for Positionals that can calculate their sum without generating all of their values like 1..100000
(I just thought sum was just too cute here to use [+] like I normally would)
say(…) call the .gist method on its input, and prints it with an additional newline.

What is it perl 5?

this reads like lolcode

@Lembik it is clearly labeled as Perl 6, which is a sister language to Perl 5.

There was a typo. I meant what is it in Perl 5?

Well $a+=$_ for <>;print $a works in Perl 5, but there may be a shorter way.

It is strange a Tcl guy like me ever upvoted a Perl answer!

Paste + bc, 13 bytes
paste -sd+|bc

Explanation:
paste -s        Take one line at a time from input
        d+      Joining by '+'
          |bc   Pass as expression to bc

Another shell answer!

Very neat and tidy.

Ooh, I had paste -s -d+|bc and didn't realize I could consolidate the switches. Neat!

C, 53 bytes
r;main(i){for(;~scanf("%d",&i);r+=i);printf("%d",r);}

C showing its credentials again :)

I feel like there should be a shorter way, but I don't see it :)

Python 3, 28 bytes
print(sum(map(int,open(0))))

Taken from this tip. I've been told this won't work on Windows.
Try it online!

I learned something new!

Retina, 11 7 bytes
-4 thanks to Martin Ender
.*
$*
1

Try it online!

Convert to unary:
.*
$*

Count the number of 1s:
1

Interesting how Retina, as a regex based language, can do the sum in fewer bytes than the shortest bash answer posted so far. +1

Is this reading from standard in?

@Lembik Yes it is.

If input in unary was allowed, it'd be only one byte.

@mbomb007 I already tried that in sed.

Brain-Flak, 20 bytes
(([]){[{}]{}([])}{})

Try it online!
Explanation
This is a golf off of a solution made by Riley in chat.  His solution was:
([])({<{}>{}<([])>}{})

If your familiar with Brain-Flak this is pretty self-explanatory.  It pushes the stack height and pops one value as it counts down, at the end it pushes the sum of all the runs.
It is a pretty good golf but he zeros both {} and ([]) however these will have a values that only differ by one so if instead we remove the masks and make one of the two negative they should nearly cancel out.
([])({[{}]{}([])}{})

Since they always differ by one we have the unfortunate circumstance where our answer is always off by the stack height.  In order to remedy this we simply move the beginning of the push to encompass the first stack height.
(([]){[{}]{}([])}{})

I thought of it as the negative pop cancels the previous height pushed (from before the loop, or the end of the previous time through), and the last height is 0 so it can be ignored.

Python 2, 40 bytes
import sys;print sum(map(int,sys.stdin))

Perl 5, 9 bytes
8 bytes of code + -p flag.
$\+=$_}{

Try it online!
With -p, the input is read one line at a time, stored in $_ each time. We use $\ as accumulator, because thanks to -p flag, it's implicitly printed at the end. The unmatched }{ are used so -p flag only prints $\ once at the end instead of printing $_ and $\ at each line it reads like it normally does.

I can't even parse it! :) Explanation please.

@Lembik Here you go.

The unmatched parenthesise part is very obscure!

@Lembik Those aren't parenthesizes... They're either French or Curly Braces depends on who you ask, but they definitely are not )(

I have never heard them called French. I wonder what the French call them?

@Lembik accolades, apparently.

Pure Bash, 37 36 bytes
Thanks to @KevinCruijssen for a byte!
while read a;do((b+=a));done;echo $b

Try it online!

Very nice and clean.

I never program in Bash, but isn't it possible to remove the space between do ((? The TIO seems to work.

@KevinCruijssen Yeah, it seems like it works. I use zsh as my daily shell and it doesn't work in zsh without a space, I just assumed it wouldn't work in Bash but apparently it does.

R,11 bytes
sum(scan())

scan takes the input, one number per line. And sum, well, sums.

Haskell, 32 bytes
interact$show.sum.map read.lines

Try it online!.
interact collects the whole input from stdin, passes it to the function given as its argument and prints the string it gets back from this function. The function is:
            lines   -- split input into list of lines at nl
      map read      -- convert every line to a number (read is polymorphic,
                    -- but as want to sum it later, the type checker knows
                    -- it has to be numbers)
    sum             -- sum the list of numbers
show                -- convert back to string

This makes me really like Haskell. In Scala, I have to do lines.map(_.toInt)
because sum expects some sort of numeric implicit conversion from String or in this case an explicit one.

PHP, 22 bytes
<?=array_sum(file(t));

This assumes there is a file named "t" with a list of integers.
file() opens a file and returns an array with each line stored a separate element in the array. array_sum() sums all the elements in an array.

Awk, 19 bytes
{s+=$1}END{print s}

Explanation:
{s+=$1}                For all lines in the input, add to s
        END             End loop
           {print s}    Print s

"Explanation coming soon™" That'd be my new catchphrase if it weren't trademarked...

In the language of awk, your answer is actually only 19 bytes: {s+=$1}END{print s} :)

dc, 14 bytes
0[+?z2=a]dsaxp

Try it online!
Explanation:
 [      ] sa   # recursive macro stored in register a, does the following:
  +            # - sum both numbers on stack
               #   (prints to stderr 1st time since there's only 1)
   ?           # - read next line, push to stack as number
    z          # - push size of stack
     2         # - push 2
      =a       # - if stack size = 2, ? yielded something, so recurse
               # - otherwise end macro (implicit)
0              # push 0 (accumulator)
         d     # duplicate macro before storing it
            x  # Call macro
             p # The sum should be on the stack now, so print it

Python, 38 30 bytes
lambda n:sum(map(int,open(n)))

In python, files are opened by open('filename') (obviously). They are, however, iterables. Each time you iterate through the file, you get the next line.  So map iterates over each list, calling int on it, and then sums the resulting list.
Call with the filename as input. (i.e. f('numbers.txt'))
8 bytes saved by using map(int, open(n)) instead of a list comprehension. Original code:
lambda n:sum([int(i)for i in open(n)])

I believe that you can also do this with standard input by calling 'open(0)'. Not sure if that can be used to shorten your answer.

@Cole dennis already has that solution, so I'll leave my answer like this.

My mistake, sorry about that; I didn't read all the way through before coming to your answer.

@Cole it's okay, I don't mind.

Pure bash, 30
read -d_ b
echo $[${b//'
'/+}]

Try it online.

reads the input file in one go into the variable b. -d_ tells read that the line delimiter is _ instead of newline
${b//'newline'/+} replaces the newlines in b with +
echo $[ ... ] arithmetically evaluates the resulting expression and outputs it.

+1 Very nice. Is the trailing newline of a input file read as well? I ask because if it is replaced by '+', the $[] section will error due to a trailing '+'.

@seshoumara It appears that read discards final trailing newlines, even though the line delimiter is overridden to _.  This is perhaps a caveat of read, but it works well for this situation.

I am always happy to see a pure bash solution.

CJam, 5 bytes
q~]1b

Try it online!
How it works
q     e# Read all input from STDIN.
 ~    e# Evaluate that input, pushing several integers.
  ]   e# Wrap the entire stack in an array.
   1b e# Convert from base 1 to integer.
      e# :+ (reduce by sum) would work as well, but 1b handles empty arrays.

How does 1b sum numbers?

CJam doesn't require a canonical representation for digits-to-integer conversion; [<x> <y> <z> <w>]<b>b simply computes b³x + b²y + bz + w. When b = 1, this gives x + y + z + w.

Mathematica, 19 bytes
Assumes Mathematica's notebook environment.
Tr[#&@@@Import@"a"]

Expects the input to be in a file a.

It's a crazy language :)

@Lembik normal people would write this very readably as Total @ Flatten @ Import @ "a" or even "a" // Import // Flatten // Total. ;)

Wouldn't Tr[#&@@@Import@#]& also be allowed?

Jelly, 9 8 bytes
ƈFÐ¿FỴVS

STDIN isn't really Jelly's thing...
Try it online!
How it works
ƈFÐ¿FỴVS  Main link. No arguments. Implicit argument: 0

  Ð¿      While loop; while the condition returns a truthy value, execute the body
          and set the return value to the result. Collect all results (including 0,
          the initial return value) in an array and return that array.
ƈ           Body: Yield a character from STDIN or [] if the input is exhausted.
 F          Condition: Flatten, mapping 0 to [], '0' to "0", and [] to [] (falsy).
    F     Flatten the result.
     Ỵ    Split at newlines.
      V   Evaluate the resulting strings.
       S  Take the sum.

The second F could be a Ṗ as well, for clarity.

Brachylog, 4 bytes
ṇịᵐ+

Try it online!
Explanation
ṇ         Split the Input on linebreaks
 ịᵐ       Map: String to Integer
   +      Sum

Vim, 16 bytes/keystrokes
:%s/\n/+
C<C-r>=<C-r>"<C-h>

Since V is backwards compatible, you can Try it online!

Is this either reading from standard in or from a file?

Yeah, Vim might not be allowed...:(

dc, 22
[pq]sq0[?z2>q+lmx]dsmx

This seems rather longer than it should be, but it is tricky to decide when the end of the file is reached.  The only way I can think of to do this is check the stack length after the ? command.
Try it online.
[pq]                    # macro to `p`rint top-of-stack, then `q`uit the program
    sq                  # save the above macro in the `q` register
      0                 # push `0` to the stack.  Each input number is added to this (stack accumulator)
       [         ]      # macro to:
        ?               # - read line of input
         z              # - push stack length to stack
          2             # - push 2 to the stack
           >q           # - if 2 > stack length then invoke macro stored in `q` register
             +          # - add input to stack accumulator
              lmx       # - load macro stored in `m` register and execute it
                  d     # duplicate macro
                   sm   # store in register `m`
                     x  # execute macro

Note the macro m is called recursively.  Modern dc implements tail recursion for this sort of thing, so there should be no worries about overflowing the stack.

Welcome to PPCG! Please note that if there isn't enough explanations it will go through the low quality posts filter.

@SIGSEGV no welcome necessary - I've been here a while ;-).  Yep, I was writing my explanation while you commented.  See edit.

I owe you a byte for the trick of duplicating the macro before storing it.

Pyth, 3 bytes
s.Q

Try it online!
 .Q  Read all of standard input, evaluating each line.
s    Take the sum.

jq, 5 bytes
add, plus the command line flag -s.
For example:
% echo "1\n2\n3\n4\n5" | jq -s add
15

6 bytes.  Since -sadd won't work, count the space.

@agc Correct me if I'm wrong but the code itself is add (3 bytes) and you have to add 2 bytes for the -s flag. The space doesn't count as the code or the flag: it's the command line separator used by the language.

@ThisGuy, Well the -s flag is short for "--slurp", (read the entire input stream into a large array and run the filter just once), which changes both how jq interprets the input data, and how it runs the code.  It's not like the -ein sed which merely tells sed that the subsequent string is code.  The -s is more like a part of the jq language itself, and therefore that 6th byte space would be too.

Ruby, 19 15 bytes
Loving that new #sum in Ruby 2.4 :)
p$<.sum(&:to_i)

This program accepts input from either stdin or any filename(s) given as command line argument

For those of us without 2.4 (including TIO…) p$<.map(&:to_i).inject(:+)

Actually, 2 bytes
kΣ

Try it online!
Explanation:
kΣ
    (implicit input - read each line, evaluate it, and push it to the stack)
k   pop all stack elements and push them as a list
 Σ  sum
    (implicit output)

Python 2, 50 45 43 bytes
Pretty self-explanatory.
s=0
try:
    while 1:s+=input()
except:print s

Try it online

I think any error suffices for break, since programs can terminate in error by default. An unitialized variable would do.

Better yet, the while can be in the try block.

Use only 1 space before while 1:. If you're using tabs SE messes them up.

@CalculatorFeline If you "edit" the post you can see it's a real tab. You can also see it's a real tab on TIO. I prefer tabs to spaces.

Good to know.``

Pyke, 4 bytes
zbrs

Try it online!
z    -   input()
 b   -  int(^)
  r  - if no errors: goto start
   s - sum(stack)

Cubix, 15 bytes
I have two versions to do this.  The first (and longest) is to specification.  This will work with non negative integers only.  A negative integer will be treated as a end of input, but zeros will be handled correctly.
O<u;Ii?;+...@._

Try it here
Expanded onto the cube
    O <
    u ;
I i ? ; + . . .
@ . _ . . . . .
    . .
    . .

This essentially reads in an integer and the seperator.  If the separator is negative (EOF or negative) redirect up into a path that will remove two items from the stack, output the already summed results, grab a superfluous input and exit.  Otherwise if the input is non negative remove from the stack then sum.  This creates a rolling total.
The shorter (8 byte) non-compliant version will handle non-zero integers, but it treats 0 on the stack as the end of input.
@O;UI!W+

Try it here
    @ O
    ; U
I ! W + . . . .
. . . . . . . .
    . .
    . .

C#, 121 bytes
Java, but no C#? That will not do...
using C=System.Console;class P{static void Main(){int a=0,b;for(;int.TryParse(C.ReadLine(),out b);)a+=b;C.WriteLine(a);}}

Try it Online
Since this score is worse than Java's, we'd better provide a 95 byte context-less function also:
using C=System.Console;int S(){int a=0,b;for(;int.TryParse(C.ReadLine(),out b);)a+=b;return a;}

Formatted and commented:
using C=System.Console;

class P
{
    static void Main()
    {
        int a=0,b; // a is accumulator, b is tempory storage
        for(;int.TryParse(C.ReadLine(),out b);) // read a line, try to parse it as an integer (expects a trailing new-line)
            a+=b; // add to accumulator
        C.WriteLine(a); // print accumulator
    }
}

I was really hoping to have some code like the following:
int a=0,b=0,c;
for(;(c=C.Read())>0;)
    b=c<15?(a+=b)*0:b*10+c-48;
C.WriteLine(a);

But it just doesn't pay :(
Just for fun, the try...catch solution is also 121 bytes
using C=System.Console;class P{static void Main(){int a=0;try{for(;;)a+=int.Parse(C.ReadLine());}catch{}C.WriteLine(a);}}

Pip, 4 bytes
3 bytes of code, +1 for -r flag.
$+g

Try it online!
$+g is the standard "sum all inputs" program--read it as fold-plus(arglist). Normally the arglist is taken from command-line arguments. The -r flag takes it from lines of stdin instead.

PostScript, 11
Consists of two files.
File A: (2 bytes)
0[

File B: (8 bytes tokenized)
]{add}forall =

Invoke as: (1 byte for extra file)
$ gs a inputfile b

This takes advantage of the fact that the input format is also valid PostScript code that just pushes all the numbers on the stack.
This allows it to very cheaply create an array from them over which it can iterate, by using multiple files to place an initial value for the summation and the opening brace on the stack before the input file.

Thank you.  Can you do it in pdf too?

@Lembik I'll see, it's a bit harder to do actual computation in PDF since it only contains a subset of the operators and a bunch of security limitations.

Go, 146 bytes
package main
import("bufio";"os";"strconv")
func main(){
s:=bufio.NewScanner(os.Stdin)
n:=0
for s.Scan(){m,_:=strconv.Atoi(s.Text())
n+=m
print(n)}}

GS2, 2 bytes
Wd

Try it online!
How it works
    (implicit) Read all input from STDIN an push it as a string.
W   Extract all integers, pushing a single array.
    For input x, this executes map(int, re.findall(r'-?\d+', x)) internally.
 d  Take the sum.

GNU sed + bc, 34 bytes
:
$!N
$!b
y:\n:+:
s:.*:echo &|bc:e

Try it online!
It is possible to do a shell call from inside sed, and as such I use bc to calculate the sum. Lines 1 to 4 only prepare the input necessary for that calculation. This works for negative numbers as well.
Explanation:
:                    # start reading loop
$!N                  # if not EOF, read and append a new input line to pattern
$!b                  # repeat
y:\n:+:              # turn all newlines into pluses
s:.*:echo &|bc:e     # shell call to bc with pattern as input (calculates sum)
                     # implicit printing

Pure GNU sed program: 236 + 1(r flag) = 237 bytes (as promised some time ago)
There are no data types or any math operations in sed. I have tried various methods, but it turns out that concatenating the numbers in unary format and converting the result back to decimal is the simplest way. This works for non-negative integers only, compared to the code above, however this is precisely what the challenge stated in the first place.
G;s:\n::
# concatenate current decimal number with the intermediary unary sum, if any
h;:;s:\w::2g;y:9876543210:87654321\t :;/ /!s:;|$:@:;/\s/!t;x;s:.::;x;G;s:;.*::m;s:\s::g;/\w/{s:@:&&&&&&&&&&:g;t}
# convert the decimal number to unary (using '@' as digit)
y:@:;:
# change unary digit from '@' to ';', to not interfere with above on the next cycle
h;$!d
# store intermediary unary sum and start next reading cycle if input lines left
s:^:0:;/;/{:d;s:^9+:0&:;s:.9*;:/&:;h;s:.*/::;y:0123456789:1234567890:;x;s:/.*::;G;s:\n::;s:;::;/;/td}
# convert final unary sum to decimal (result), plus implicit printing at the end

Try it online!
The program does bignum arithmetic, as long as sed can store in memory the unary result.

Powershell, 18 Bytes
(gc 1)-join"+"|iex

this assumes the file is named '1' with no extension.
alternate 24 byte version, takes filename as input:
(gc "$args")-join"+"|iex

explanation:
( get content of the file "$args" ) then -join the lines together with a "+" to form a valid-syntax sum, then | invoke expression to calculate it as if it was typed into the console directly.
if output is allowed in the following format:
Count    : 3
Average  :
Sum      : 227
Maximum  :
Minimum  :
Property :

then gc 1|measure -s is a valid 15 byte solution, thanks to @AdmBorkBork for pointing that out.

Your 18 byte version is valid.

@Lembik Thanks, wasn't 100% sure if the no-extension would be allowed, updated the answer there.

If extraneous output is allowed, you can do gc 1|measure -s for 15

@Lembik see AdmBorkBork's suggestion, if all the 'extra' text is allowed let me know and I can update my answer, thanks!

I don't think that is allowed but it is nice.

@Lembik thanks for clearing that up - i'll leave it as a note anyway as it is interesting.

Batch, 55 bytes
@set s=0
@for /f %%n in (%1)do @set/as+=%%n
@echo %s%

Takes the file to be summed as a command-line parameter.

Do you have to do set s=0 in the beginning? It will work on the first run without it, won't it?

@KodosJohnson I'm not sure that's legal in code golf; as I recall the same applies to being able to call a function more than once without the caller resetting global variables to zero in between.

MATLAB: 17 bytes
sum(dlmread('x'))

Assumes a file named 'x' in current directory. dlmread reads numeric values from a file using delimiters - if no delimiter is specified as the second argument, it will infer from the file type. It successfully infers \n as the delimiter in a file as specified by the question, then uses sum to add them up.

QBasic 4.5, 61 59 bytes
Since QBasic isn't the greatest with streams, the input is assumed in a file called "a".
Minus 2 bytes because @DLosc showed me an alternate syntax for one of QBasic's most iconic commands. Does QBasic really hold no secrets for you?
OPEN"I",1,"a"
WHILE EOF(1)=0:INPUT#1,b$:x=x+VAL(b$)
WEND:?x

QBIC, 19 bytes
{_?~A=Z|_Xp\p=p+!A!

Explanation
{        DO infinitely
_?       Ask for user input, save as A$
~A=Z     IF input was nothing (Z$ = "")
|_Xp     THEN QUIT, printing the total
\p=p+    ELSE increase the total by
     A   the given input
    ! !  cast as a number

Tcl, 33 bytes
puts [expr [join [read stdin] +]]

Try it online!

Java 7, 109 Bytes
import java.util.*;int x;int s(){Scanner a=new
Scanner(System.in);while(a.hasNext())x+=a.nextInt();return x;}

Try it!
Reads from System.in

T-SQL, 60 59 bytes
SELECT 0a INTO n;BULK INSERT n FROM'd:n'SELECT SUM(a)FROM n

This is the kind of thing that SQL was designed to do, surprised there isn't already an answer for it. Tested on MS SQL 2012.
SELECT 0a INTO n; is slightly shorter than CREATE TABLE n(a INT). Adding a zero row doesn't change the total.
Text file named n (no extension) is located in the current folder on the D: drive. BULK INSERT is shorter and easier than other file import options like SELECT FROM OPENROWSET(BULK) or EXEC xp_cmdshell 'bcp.exe'.
Of course if input is allowed via a pre-existing table, per our normal I/O standards, then this would be trivial (19 bytes):
SELECT SUM(a)FROM n

But of course this challenge is all about the IO...

Implicit, 4 3 bytes
©1Þ

I'm going to add a builtin for ©1 eventually (e.g. when I'm done working on bitwise). (Just kidding, I'm never going to get around to it.)
Explanation:
©1Þ
©1   consume all input as integers
  Þ  sum the entire stack

Try it online!

Scala, 48 bytes
print(io.Source.stdin.getLines.map(_.toInt).sum)

JavaScript (Node.js), 112 bytes
Improvements upon the other JavaScript answer and comment below it.
a=0
require('readline').createInterface({input:process.stdin}).on('line',l=>a+=+l).on('close',_=>console.log(a))

Try it online!
Given the split module (npm install split), it's much shorter:
JavaScript (Node.js) with split module, 90 bytes
a=0
process.stdin.pipe(require('split')()).on('data',l=>a+=+l).on('end',_=>console.log(a))

REXX, 47 bytes
s=0
pull n
do until n=''
  s=s+n
  pull n
  end
say s

Alice, 11 bytes
/o
\i@/Hd&+

Try it online!
This feels a bit suboptimal with all those mirrors (and also because the H could also be a +, possibly allowing reuse there), but so far I've only found a handful of different 11-byte solutions.
Explanation
/o
\i@/...

While it's sometimes possible to shorten it, this seems to be a good pattern for programs which a) one or more integers as input, b) transform them with a linear program in Cardinal mode (i.e. integer processing mode), c) want to output one integer. The instruction pointer (IP) first moves from / to / bouncing through the i which reads all input. Then the ... is executed and the IP wrap around to the wrong. The \ puts the IP again in Ordinal mode where o prints the integer as a decimal string and @ terminates the program. So that's the framework I'm using here.
The core of the program is then just four commands:
H   Compute the absolute value of the top of the stack. The reason we're doing this
    is that the stack still holds the entire input as a string. But as soon as you
    try to pop a value in Cardinal mode, that string gets implicitly converted
    to the integers it contains. So in this case, the H itself doesn't really
    do anything but it forces the input to be converted. We could also use
    + here and already sum the top two values (if there's only one value it
    would get added to an implicit zero, so that's fine).
d   Push the stack depth, i.e. the number of integers in the input.
&   Execute the next command that many times.
+   Add the top two numbers of the stack. Of course this is one more addition
    than we need, but there are only implicit zeros beneath the input so
    they don't change the result.

Labyrinth, 8 bytes
?+
;,;!@

Try it online!
The left-most 2x2 block is the main loop:
?   Read integer.
+   Add to running total (initially zero).
,   Read character. 10 as long as there is another input, -1 at EOF which will
    exit the loop.
;   Discard the 10.

Once we hit EOF, the IP moves east from the ,.
;   Discard the -1.
!   Output the sum.
@   Terminate the program.

Java 7, 111 bytes
import java.util.*;int c(){Scanner c=new Scanner(System.in);int r=0;for(;c.hasNext();r+=c.nextInt());return r;}

Takes the input from STDIN.
Try it here.

Java, the black sheep of the golfing family :)

@Lembik Yep.. I can usually compete with BrainFuck, C# and other longer languages, but Java certainly will never win a golfing contest. The only accepted Java answer I've seen so far was for a [popularity-contest]. But it's still fun to golf in Java imo, and once in a while something is pretty short compared to other submissions - in Java 8 that is :)

JavaScript (Node.js), 124 bytes
t=0;
r=require('readline').createInterface({input:process.stdin});
r.on('line',l=>{t-=-l});
r.on('close',()=>console.log(t))

Try it online!

119 bytes: t=0;with(require('readline').createInterface({input:process.stdin}))on('line',l=>{t-=-l}),on('close',_=>console.log(t))

@IsmaelMiguel You can do even better with chaining, so: my answer.

Julia, 44 bytes
print(sum(map(s->parse(Int,s),readlines())))

A Julia answer is very warmly welcomed!

Jellyfish, 24 bytes
p
/
+
j, ,']
1'[J-1
   0

Try it online!
Explanation
Reading input isn't very flexible in Jellyfish. In particular, there's no easy way to read a variable number of integers from STDIN, except as a list literal. So the majority of this code is input.
The shortest way I've found is to read all of STDIN as a string, then wrap it in [...] and then evaluate the string. Thankfully, Jelly's parser only looks for whitespace as a separator in lists, not specifically for space characters. So the linefeed separation required by the challenge works.
So let's build up the code from the bottom:
   J-1
   0

Read all input.
   ,']
   J-1
   0

Append ].
 , ,']
 '[J-1
   0

Prepend [.
j, ,']
1'[J-1
   0

Evaluate.
/
+
j, ,']
1'[J-1
   0

Fold addition (in other words, sum).
p
/
+
j, ,']
1'[J-1
   0

Print the result.

C++, 99 Bytes
using namespace std;int main(){string a;int b=0;while(1){getline(cin,a);cout<<(b+=stoi(a))<<"\n";}}

Not my finest work, and there's probably a far better way to go about doing this. Still, I figured that using a string was the optimal way of doing things, seeing as I felt conversions with 'cin' would take up a vast majority of my code otherwise.
Enjoy!

You could save a few bytes by just wrapping the function in namespace std{ and declaring the function as ::main, rather than using using.

Triangular, 15 bytes
(\$]U]P.%p/+U(<

Try it online!
Formats into this triangle:
    (
   \ $
  ] U ]
 P . % p
/ + U ( <

Explanation:
The IP starts from the top of the triangle, moving Southeast. So the first code that is executed is this:
($]

That simply reads integers as input until there is no more input.
This is how the interpreter sees the next part:
p(U+P]U%

p pops the EOF from the stack.
( opens a loop (to add the inputted integers).
U pulls the "memory" (register) value onto the stack if it is not zero.
+ adds the top two stack values together, pops them, and pushes the result.
P pops the top of stack into memory. Now, if we've added all inputted integers together, nothing will be on the stack.
] ends the loop if the top of the stack is falsy  (or the stack is empty).
U pulls the memory value onto the stack.
% prints it.
Another loop is created at the end of the code, but that doesn't do anything as the IP runs off the playing field and terminates.

JavaScript (Node.js), 78 bytes
process.stdin.on("data",r=>console.log((""+r).split`
`.reduce((a,v)=>+a+ +v)))

No requires needed for this one, just native NodeJS.
Try it online!

Dart, 96 bytes (non async), 132 bytes (async)
Non async:
import'dart:io';main(){_ s;_ i=0;while((s=stdin.readLineSync())!=null)i+=int.parse(s);print(i);}

Dart allows you to define local variables with types that don't exist when running in uncheck mode (which is the default mode). This program doesn't function in checked mode.
Async:
import'dart:io';import'dart:convert';main()async=>print((await UTF8.decodeStream(stdin)).split("\n").fold(0,(p,e)=>p+int.parse(e)));

The async version is longer, easier to read, and faster than the sync version. It also works in checked mode. UTF8.decodeStream decodes the entire stream into a Future, await waits for this to finish and gives a String, the string is split by line into List, and finally the strings are folded into the final result.

Lua, 59 bytes 57 bytes
New code: 57 bytes
i,s=0,0;repeat i,s=i+s,io.read("*l")until not s print(i)

We initialize i and s to 0. For each iteration, we add s to i and load in a new s from stdin. Lua has implicit string -> number coercions when doing numeric operations on a string.

Old code: 59 bytes
i=0;io.read("*a"):gsub(".-\n",function(g)i=i+g end)print(i)

Takes entire stdin and turns it into a string, gsubs over the entire string to extract lines, uses implicit number conversion and adds the lines to i, then prints i.

Carrot, 6 bytes
#^A
+

Note the trailing space after the +.
Explanation:
#   //Set the stack to the entire input
^   //Convert to operations mode
A\n //Split the stack into an array on a new line
+   //Add all the arguments of the array together
    //Implicitly output the result

This is one of the reasons I am doing the rewrite of Carrot. With the new lexer, the space after + would not be needed as it will be understood that + takes no arguments.

@Cowsquack Ah nice that'll be good.

Ly, 2 bytes
&+

Try it online!
A Ly builtin that would beat the accepted answer if it wasn't a 2-byte builtin...

q/kdb+, 14 bytes
Solution:
sum"J"$(0:)`:f

Example:
q)system "cat f" / check contents of file f
"123"
,"5"
"99"
q)sum"J"$(0:)`:f
227

Explanation:
Read in the file called f, cast to longs, sum up:
sum"J"$read0`:f / ungolfed solution
            `:f / our input file f
       read0    / read in a file, break on newlines
   "J"$         / parse strings to longs
sum             / sum it up

Bonus:
The solution in K4 is 10 bytes. Eequivalent to sum value each read0 `:f in Q:
+/.:'0:`:f

Wumpus, 11 8 bytes
I+0i.
O@

Try it online!
Explanation
As long as there are numbers left to read, the program loops through the first line:
I   Read a decimal integer from STDIN.
+   Add it to the top of the stack. Initially, the stack is empty, which adds
    the first number to an implicit zero.
0   Push 0.
i   Read the next byte. If there are numbers left, this will be a 10 (for the
    separating linefeed). Otherwise, we're at EOF and this gives -1.
.   Jump to (0, x), where x is the byte we just read, modulo 2 (because the
    program is 2 rows tall). So for a linefeed, this jumps to the beginning
    of the first line, and at EOF this jumps to the beginning of the second
    line.

Once we run out of numbers to add, control flow goes to the second line:
O   Print the sum as a decimal integer.
@   Terminate the program.

Flobnar, 16 12 bytes
-4 bytes thanks to @JoKing
+>p*
^@
>&06

Try it online! Requires the -d flag.
As a bonus, this works if no numbers are passed, and supports pretty much any separator other than digits and -.

12 bytes

@JoKing I have no idea how that works, but ok...

APL (Dyalog Unicode), 12 bytes
Complete program.
+/⍎⍕⊃⎕NGET⍞1

Try it online!
⍞ read filename from stdin
⊃⎕NGET…1 get native file content as list of strings
⍕ stringify (puts two spaces between lines)
⍎ execute (as APL code)
+/ sum

Vyxal, 3 bytes
wJ∑

Try it Online!
Explained
wJ∑
w   # list
 J  # merge
  ∑ # sum

Sinclair ZX81 (16K only - probably*) File size according to EightyOne - 163** bytes (yes 163!) Byte count undetermined
Firstly, we should make our file, so using direct mode, type:
LET A=123
LET B=5
LET C=99

To make sure that they are there, print them to the screen, as follows:
PRINT A,,B,,C

This should appear on the display:

Now, to save this to file (as the variable stack is saved along with other important memory locations used by the interpreter), simply type:
SAVE "SUM"

If you're using a real ZX81 then press play and record on tape, whilst emulators like EightyOne will create a tape image for you.
Now clear the RAMs with:
RAND USR 0

or:
NEW

Now rewind the tape (or the emulator should auto-detect and start the virtual tape from the beginning), and type:
LOAD "SUM"

So our file is back in memories, so we need to add it together. Simply:
PRINT A+B+C

And the answer is:

*I specify 16K because any less and the ZX81 will typically rearrange the memory and this could affect the var stack (mostly to do with collapsing the DFILE), as the DFILE is static with 16K then this should be less of an issue.
**The ZX81 file is saving more than just the VAR stack of three whole variables above, and although each number appears to be an integer, the ZX81 is storing these variables as 24-bit floating point numbers rather than 1 byte integers.

Utterly brilliant . Let's not mention the spec :)

I'm confused what the actual code is. Is that PRINT A+B+C part of it? Would it be invalid then if there are more or less than 3 numbers?

The challenge seemed to specifically require a file, and to do that on a ZX81 you need to save your values somewhere. I decided to use the 24-bit floating point variables that I named A, B, and C. I could have POKEd these values to a spare bit of memory but I'm not sure if it'll save. So if you wanted more variables, then you'd need to initialise and declare more variables, so if LET D=321 and that was SAVEd then to add up the file contents, one would PRINT A+B+C+D. I could save to a string but I'd been some way to separate each individual number by a comma, for instance.

Remember, I initialised and declared the variable values, then saved that to a file before clearing the memory. I then loaded back the file using the ZX81's equivalent of standard in - once the file was loaded, the variables were back in memory, so therefore I could use the PRINT keyword to add up and output the values.

@ShaunBebbers The same program needs to work for an arbitrary number of values without modification.

So how to create files and read them on a ZX81 then... Okay back to 101.

Also note that the program must use the input format specified in the question.

Sure but programming standards were very different in 1981 - standard in? INPUT A then.

This is why I suggested having one liners and golfing in the Retro Computing stack exchange.

Anyfix, 4 bytes
ɦ€#S

Explanation
ɦ€#S  Program
ɦ     Exhaust input; read into a list of lines
 €    Map:
  #        Parse to number
   S  Sum

JavaScript (ES6), 27 bytes
s=>eval(s.split`
`.join`+`)

Try it

f=
s=>eval(s.split`
`.join`+`)
oninput=_=>o.innerText=f(i.value);o.innerText=f(i.value=`123\n5\n99`)
textarea{font-family:sans-serif;height:100px;width:100px;}
<textarea id=i></textarea><pre id=o>

Explanation

Takes input as a multiline string via parameter s.
Splits the string to an array on newlines.
Joins the array to a string on +.
Evals the string to give us the sum.

Alternative, 23 bytes
If we could take each integer as an individual argument of our function then we could do this:
(...a)=>eval(a.join`+`)

Alternative, 63 bytes
If we have to take a file name as input then use this version instead:
p=>fetch(p).then(r=>r.text()).then(s=>eval(s.split`
`.join`+`))

Stax, 2 bytes
|+

Run and debug it
Also prints intermediate results, which doesn't appear to be disallowed

C++, 98 bytes
#include<regex>
namespace std{int::main(){istream_iterator<int>a{cin},b;cout<<accumulate(a,b,0);}}

Ungolfed
#include <iterator>
#include <numeric>
#include <iostream>

int main()
{
    std::istream_iterator<int> first{std::cin};
    std::istream_iterator<int> last{};
    std::cout << std::accumulate(first, last, 0);
}

We have std::istream_iterator to read input as whitespace-separated integers, and std::accumulate to add them up.

Ahead, 13 bytes
~Ilj~#
 >K+O@

Try it online!

Scheme, 48 bytes
(write(let l((x 0))(if(real? x)(+(l(read))x)0)))

Try it online! (Chicken Scheme, but this works on other schemes as well)
(write ... ) write to STDOUT the result of

(let l ... ) looping special form named l

((x 0)) initially declare x as 0

(if ... ) if

(real? x) x is real, i.e. not EOF,

(+ ... ) add

(l(read)) the result of this loop called with x set as the value read from STDIN

x with x

0 else give 0

Flurry, 24 bytes
[]{{}[<><<>()>]{}}[<>()]

Run example
$ printf "11\n12\n13" | ./flurry -nii -c "[]{{}[<><<>()>]{}}[<>()]"
36

The integer input mode handles the input format requirement. Then it is straightforward reduction over the stack.
// Reduce the stack by running <pop and add to the current value>
// <stack height> times
main = height pop_add 0
height = []
pop_add = \x. x succ pop = {{}[<><<>()>]{}} // add x y = x succ y
0 = (SK) = [<>()]

J-uby, 13 bytes
Port of Daniero’s Ruby answer.
:sum+Z|-:p^$<

Attempt This Online!

J, 18 bytes
1#.0".&>;:@stdin''

Attempt This Online!
1#.0".&>;:@stdin''
           stdin''  NB. self-explanatory
          @         NB. then
        ;:          NB. split into words, J boxes each int and each LF
      &>            NB. for every box
   0".              NB. eval the item as J code and fallback to 0
1#.                 NB. sum the result

Thunno 2 S, 1 byte
¤

Attempt This Online!
Or, 2 bytes flagless:
¤S

Attempt This Online!


text:
TiB, not TB, Seriously?
If you're like me (and/or use Windows), You should have found this issue quite disturbing.
You plug in a hard drive (2TB for my occasion), and realize it doesn't show as 2TB, but a bit smaller size which is clearly not 2TB.
Over some research, I found it was because of Microsoft's mistake. Mistyping Binary prefix as Decimal prefixes. (i.e. They typed 1TiB as 1TB)
So, I would like to see a Binary prefix to Decimal prefix program. Since this is a big problem (and some computers are literally toasters), You have to make your program as short as possible.
conversion chart I found

I/O
You will be given the size (positive real number, will not exceed 2ˆ16 when converted), and the unit (4 of them, KiB, MiB, GiB and TiB, each corresponds to 1024ˆ1, 1024ˆ2, 1024ˆ3 and 1024ˆ4 bytes)
You have to output the (decimal representation of) the size (rounded half-up to integer value), and the corresponding unit.

Examples
678 MiB => 711 MB
1.8 TiB => 2 TB

Tip: Google has a unit converter

This needs more specification. What units do we have to handle? What number ranges? With what precision?

@xnor precision is specified(rounded half-up to integer value), everything else is edited to specify

Better, but there's more to specify. How much precision can the inputs be given with? Can they be negative? Can an input be given like .15? 1.00? What about outputs? There's a bunch of things like this to pin down. I'd suggest moving it to the sandbox.

Rounding an precision are different. You use fractional terabytes but entire megabytes in your examples.

@Dennis Huh? I don't understand what you mean.

Why is the first output 711 MB and not 710.9 MB?

@Dennis specified: rounded half-up to integer value

So the output for 1.4 TiB would be 2 TB?

@Dennis Yup. 1.4 TiB=> 1.5...TB => 2TB.

What would the output for 999 MiB be?

@Dennis 1048 it is.

TiB or not TiB, that is the question.

@SIGSEGV So we don't have to "jump" prefixes? You should clarify that in the challenge spec.

Calling the discrepancy "Microsoft's horrible mistake" is somewhat flamebait. All they're doing is maintaining backwards compatibility with what us old-timers (read: anyone in their 30s or up) grew up knowing as the standard.

Yeah, I don't know anyone who actually calls 1024 bytes a "kibibyte". You read it Kilobytes. The existence of a decimal form/prefix at all is the real problem

Pyth, 27 25 35 Bytes
=H@z_3s[.E*v<4z^1.024x" KMGT"HdH\B

Adding the unit to the output costed me quite some bytes.
Try it!

APL (Dyalog), 26 bytes
Prompts for unit and size, and outputs unit and size.
⌊.5+⎕×1.024*'KMGT'⍳⊃⎕←⍞∩⎕A

Try it online!
∩⎕A intersection with uppercase Alphabet of
⍞ character input (unit) from STDIN
⎕← output that to STDOUT
⊃ get the first character of the outputted value
'KMGT'⍳ find the 1-based index of that in this string
1.024* raise this number that that power
⎕× multiply numeric input from STDIN with that
.5+ add a half to that
⌊ round that down

It should be 1.024 not 1.044 in your explanation

@fəˈnɛtɪk Indeed. Well spotted.

PHP, 63 bytes
<?=1.024**strpos(_KMGT,($m=$argv[2][0]))*$argv[1]+.5|0," $m",B;

takes input from command line arguments;
run with echo '<code>' | php -n or save to file and run with php -n <filename>.

Python 3.6, 78 77 bytes
a,b=input().split()
print(f'{eval(a)*1.024**" KMGT".find(b[0]):.0f} {b[0]}B')

Mathematica, 44 43 bytes
It has a built-in function for everything
Round@UnitConvert[#,StringPart[#,-3]<>"B"]&

(Input should be a string "678 MiB".)

JavaScript (ES6), 71 bytes

f=
(s,[n,[u]]=s.split` `)=>(n*1.024**` KMGT`.search(u)).toFixed()+` ${u}B`
<input oninput=o.textContent=/\s[KMGT]/.test(this.value)?f(this.value):``><span id=o>

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Safety in numbers
Write a program to determine if a periodic sequence of positive integers has the property that, for every integer n occurring in the sequence, there are never more than n other integers between two consecutive occurrences of n.
For example, 2, 3, 5, 2, 3, 6, 2, 3, 5, 2, 3, 6, ... does have this property: every pair of consecutive occurrences of 2 have at most two integers between them (such as 2, 3, 5, 2 and 2, 3, 6, 2; every pair of consecutive occurrences of 3 have at most three integers between them; and the same for 5 and 6.
However, 2, 3, 5, 2, 3, 4, 2, 3, 5, 2, 3, 4, ... does not have this property: two consecutive occurrences of 4, namely 4, 2, 3, 5, 2, 3, 4, have more than four integers between them.
Input: a reasonable representation of a periodic sequence of positive integers. For example, a finite list such as {2, 3, 5, 2, 3, 6} can represent the first infinite sequence 2, 3, 5, 2, 3, 6, 2, 3, 5, 2, 3, 6, ... above. (For that matter, the problem could be stated for finite lists that wrap around instead of for infinite periodic lists.)
Output: a truthy/falsy value.
Truthy examples:
{1}
{8, 9}
{2, 3, 4}
{5, 5, 3, 3, 6}
{2, 3, 5, 2, 3, 6}
{6, 7, 3, 5, 3, 7}
{9, 4, 6, 7, 4, 5}
{1, 1, 1, 1, 1, 100, 1}
{1, 9, 1, 8, 1, 7, 1, 11}

Falsy examples:
{1, 2, 3}
{2, 3, 9, 5}
{3, 5, 4, 4, 6}
{2, 3, 5, 2, 3, 4}
{3, 5, 7, 5, 9, 3, 7}
{5, 6, 7, 8, 9, 10, 11}
{1, 9, 1, 8, 1, 6, 1, 11}

This is codegolf, so the shortest code wins. Answers in all languages are encouraged.

Does the input list always contain at least one element?

@nimi otherwise it wouldn't represent an infinite periodic sequence.

If you take the thue-morse sequence and add any fixed positive integer greater than 1 to each term, you'll have an aperiodic infinite sequence with this property.

Haskell, 60 57 56 55 bytes
f(a:b)=b==[]||length(fst$span(/=a)b)<=a&&f b
g x=f$x++x

Assumes that the input list contains at least one element.
Usage example: g [1] -> True. Try it online!
Let a be the head of the list and b the tail. The result is True if b is empty or the number of elements at the beginning of b that are not equal to a is not greater than a and the recursive call of f b is also True, else False. Start with twice the input list.
Edit: @Leo saved 3 bytes. Thanks!
Edit 2: @Laikoni saved 1 byte. Thanks!

Using takeWhile instead of span you can avoid pattern-matching and save three bytes
Nice solution, by the way! :)

@Leo: Nice catch! Usually using span is shorter than using takeWhile, so I didn't look at it at all.

takeWhile can pretty much always be shortened to fst$span or fst.span, which saves another byte.

@Laikoni: yes of course! Thanks!

Love haskell ;)

Python, 57 56 bytes
-1 byte thanks to Dennis (replace i+1:i+v+2 with i:i-~v with an i offset of 1 from enumerate)
lambda a:all(v in(a+a)[i:i-~v]for i,v in enumerate(a,1))

Try it online!
Unnamed function taking a list, a, and testing the condition that each value, v, appears in the relevant slice to its right in a concatenation of a with itself, (a+a)[i:i-~v], where the 1-based index of v in a, i, is provided by enumerate(a,1).

That inspired an 8-byte Jelly answer. :) You can save a byte like this.

JavaScript (ES6), 67 65 55 54 51 49 bytes
Saved 3B thanks to @ETHproductions and 2B thanks to @Arnauld
a=>!a.some((b,c)=>a.concat(a).indexOf(b,++c)>b+c)

Explanation
This defines a function that takes an array a as input. Then, the .some method iterates over that array, executing another function for every element.
This inner function takes two arguments, b and c, the current value and its index. The function finds the index of the current value, starting from index c + 1. Then it checks if this index is greater than the current value plus the current index (the difference between two occurrences of the same value is greater than b). Note that this returns the exact opposite of what we want.
If one of these return values is true, the .some function returns true as well. If none of the checks return true, the .some function returns false. Once again the opposite of the value we want to return, so this result is negated and then returned.
Test it
Try all test cases here:

let f=
a=>!a.some((b,c)=>a.concat(a).indexOf(b,++c)>b+c)

let truthy = [[1], [8, 9], [2, 3, 4], [5, 5, 3, 3, 6], [2, 3, 5, 2, 3, 6], [6, 7, 3, 5, 3, 7], [9, 4, 6, 7, 4, 5], [1, 1, 1, 1, 1, 100, 1], [1, 9, 1, 8, 1, 7, 1, 11]];
let falsy  = [[1, 2, 3], [2, 3, 9, 5], [3, 5, 4, 4, 6], [2, 3, 5, 2, 3, 4], [3, 5, 7, 5, 9, 3, 7], [5, 6, 7, 8, 9, 10, 11], [1, 9, 1, 8, 1, 6, 1, 11]];

console.log("Truthy test cases:");
for (let test of truthy) {
    console.log(`${test}: ${f(test)}`);
}

console.log("Falsy test cases:");
for (let test of falsy) {
    console.log(`${test}: ${f(test)}`);
}

Very nice, that's exactly what I came up with as well :-) You can create the doubled array once at the start and use .shift() to save on the slice: a=>!a.some(b=>z.indexOf(z.shift())>b,z=a.concat(a))

Hehe, great golfers think alike ;-). I thought of using shift as well, but I didn't use it, since it turned out to be longer. Creating the double array once and shifting every time is really clever. Thanks!

Would a=>!a.some((n,i)=>a.concat(a).indexOf(n,++i)>n+i) work?

Jelly, 11 bytes
ṣZL
;çÐ€<‘P

Try it online!
How it works
;çÐ€<‘P  Main link. Argument: A (array)

;        Concatenate A with itself.
 çD€     For each n in A, call the helper with left arg. A + A and right arg. n.
     ‘   Increment all integers in A.
    <    Perform element-wise comparison of the results to both sides.
      P  Take the product of the resulting Booleans.

ṣZL      Helper link. Left argument: A. Right argument: n

ṣ        Split A at all occurrences of n.
 Z       Zip to transpose rows and columns.
  L      Length; yield the number of rows, which is equal to the number of columns
         of the input to Z.

Jelly, 8 bytes
ṙJḣ"‘Œpċ

Insipred by @JonathanAllan's Python answer.
Try it online!
How it works
ṙJḣ"‘Œpċ  Main link. Argument: A (array)

 J        Yield the indicies of A, i.e., [1, ..., len(A)].
ṙ         Rotate; yield A, rotated 1, ..., and len(A) units rotated to the left.
    ‘     Increment; add 1 to all elements of A.
  ḣ"      Head zipwith; truncate the n-th rotation to length A[n]+1.
     Œp   Take the Cartesian product of all resulting truncated rotations.
       ċ  Count the number of times A appears in the result.

Retina,  41 39 bytes
2 bytes golfed thanks to Martin Ender, which by the way introduced me to balancing groups with his fantastic guide on SO
$
,$`,
((1)+,)(?=(?<-2>1+,)*(\1|$))

^$

Input is a comma-separated list of unary numbers. Output is 0 for false and 1 for true.
Try it online! (Test suite that automatically converts from decimal)
I've recently learned about balancing groups, so I wanted to give them a try. They're not among the easiest tools to use, but sure they are powerful.
Explanation
$
,$`,

As many other submissions do, we duplicate the list to deal with wrapping. We also add a comma at the end, so every number is followed by a comma (this makes things a bit easier later)
((1)+,)(?=(?<-2>1+,)*(\1|$))

Here's where things get interesting. This is a replacement stage, we replace everything matched by the first line with the second line, in this case we are looking to remove all numbers n not followed by n+1 other different numbers.
To do so, we first match the number, capturing each 1 in a group (capturing group number 2 in this case). Then with a positive lookahead, in order to have a zero-width assertion, we repeatedly try to match in a balancing group -2, that will succeed no more than the number of captures made by group 2, a number followed by a comma. After this sequence of numbers, we are satisfied if we reach either the first number again or the end of the line.
Note: this expression could match just the final part of a number, if it doesn't manage to find a match with the full number. This is not a problem, because then the first part of the number will remain in the string and we will know that the replacement didn't completely succeed.
^$

Finally, the result should be truthy iff we have completely removed all numbers from the list. We try to match the empty string and return the number of matches found.

Nice work! :) There's no need for the \b. Removing it will cause stray matches but they'll fail to remove the entire number, so you won't end up with an empty string anyway.

@MartinEnder You're right of course, thank you :)

SWI-Prolog, 83 bytes
a(L,[H|R]):-nth0(X,R,H),H>=X,a(L,R);length(R,N),nth0(X,L,H),H>=N+X,a(L,R).
a(_,[]).

The list should be entered twice:
a([1,2,3],[1,2,3]).

If this is not considered acceptable, you may add the predicate
a(L):-a(L,L).

which adds an extra 14 bytes.
Try it online

nb: you may test for different false cases at once by separating your queries with ';' (or) and test for different true cases by separating with ',' (and)
ie, using the OP examples :
a([1],[1]),
a([8, 9],[8, 9]),
a([2, 3, 4],[2, 3, 4]),
a([5, 5, 3, 3, 6],[5, 5, 3, 3, 6]),
a([2, 3, 5, 2, 3, 6],[2, 3, 5, 2, 3, 6]),
a([6, 7, 3, 5, 3, 7],[6, 7, 3, 5, 3, 7]),
a([9, 4, 6, 7, 4, 5],[9, 4, 6, 7, 4, 5]),
a([1, 1, 1, 1, 1, 100, 1],[1, 1, 1, 1, 1, 100, 1]),
a([1, 9, 1, 8, 1, 7, 1, 11],[1, 9, 1, 8, 1, 7, 1, 11]).

and
a([1, 2, 3],[1, 2, 3]);
a([2, 3, 9, 5],[2, 3, 9, 5]);
a([3, 5, 4, 4, 6],[3, 5, 4, 4, 6]);
a([2, 3, 5, 2, 3, 4],[2, 3, 5, 2, 3, 4]);
a([3, 5, 7, 5, 9, 3, 7],[3, 5, 7, 5, 9, 3, 7]);
a([5, 6, 7, 8, 9, 10, 11],[5, 6, 7, 8, 9, 10, 11]);
a([1, 9, 1, 8, 1, 6, 1, 11],[1, 9, 1, 8, 1, 6, 1, 11]).

PHP, 52 bytes
for(;$n=$argv[++$i];$$n=$i)!$$n|$i-$$n<$n+2?:die(1);

takes sequence from command line arguments; exits with code 1 for falsy, 0 for truthy.
Run with -nr.

loop $n through arguments:

if there was no previous occurence or it was recent enough
then do nothing, else exit with code 1
remember previous occurence in $$n (variable variables)

exit with code 0 (implicit)

Crazy your variable names are invalid but I like it.

Retina, 50 bytes
$
,$`
M!&`\b(1+),.*?\b\1\b
+%`(^1*)1,1+
$1
M`1,
^0

Input as a list of comma-separate unary numbers.
Try it online!
Explanation
$
,$`

Duplicate the input so we can check steps that wrap around the end.
M!&`\b(1+),.*?\b\1\b

Match and return each (shortest) section between two identical values, e.g. 11,111,1,11.
+%`(^1*)1,1+
$1

Repeatedly remove a digit from the first number, together with an entire number after it. If the gap is small enough this will completely remove the first number. Otherwise, at least one digit will remain.
M`1,

Count how often 1, appears in all the lines. If it appears anywhere, one of the steps was too wide.
^0

Try to match a number starting with 0 (i.e. only 0 itself). This is effectively a logical negation of the output.

JavaScript (ES6), 47 bytes
a=>![...a,...a].some((n,i)=>a[-n]-(a[-n]=i)<~n)

How it works
We re-use the input array a to store the position of the last encountered occurrence of each integer in a. We use the key -n to store this position so that it does not interfere with the original indices of a.
When a[-n] exists, the actual test occurs. When a[-n] doesn't exist, the expression a[-n] - (a[-n] = i) equals undefined - i == NaN and the comparison with ~n is always falsy, which is the expected result.
Test cases

f=
a=>![...a,...a].some((n,i)=>a[-n]-(a[-n]=i)<~n)

console.log('Truthy cases:');
console.log(f([1]));
console.log(f([8, 9]));
console.log(f([2, 3, 4]));
console.log(f([5, 5, 3, 3, 6]));
console.log(f([2, 3, 5, 2, 3, 6]));
console.log(f([6, 7, 3, 5, 3, 7]));
console.log(f([9, 4, 6, 7, 4, 5]));
console.log(f([1, 1, 1, 1, 1, 100, 1]));
console.log(f([1, 9, 1, 8, 1, 7, 1, 11]));

console.log('Falsy cases:');
console.log(f([1, 2, 3]));
console.log(f([2, 3, 9, 5]));
console.log(f([3, 5, 4, 4, 6]));
console.log(f([2, 3, 5, 2, 3, 4]));
console.log(f([3, 5, 7, 5, 9, 3, 7]));
console.log(f([5, 6, 7, 8, 9, 10, 11]));
console.log(f([1, 9, 1, 8, 1, 6, 1, 11]));

Jelly, 11 bytes
ẋ2ĠṢI_2<"QȦ

Try it online!
ẋ2ĠṢI_2<"QȦ  Main link. Argument: A (array)

ẋ2           Repeat A twice to account for wrap-around.
  Ġ          Group all indices of A + A by their respective values, sorting the
             index groups by the associated values.
   Ṣ         Sort the groups lexicographically, i.e., by first appearance in A.
    I        Increments; compute the forward differences of adjacent indices in
             each of the groups.
     _2      Subtract 2 from the differences.
         Q   Unique; yield A, deduplicated.
       <"    Compare all differences in the index group corresponding to the n-th
             unique value in A with the n-th unqiue value in A.
          Ȧ  All; yield 1 if and only if none of the comparisons returned 0.

Python 3, 101 bytes
lambda l:all(v>=(l[i+1:].index(v)if v in l[i+1:]else len(l[i+1:])+l.index(v))for i,v in enumerate(l))

Try it online!

Röda, 50 bytes
f a{seq 0,#a-1|[indexOf(a[_],a[_1+1:]..a)<=a[_1]]}

Try it online!
Finally! I have been waiting for this challenge...
It's a function that returns a truthy or a falsy value. It takes one argument, the array.
It iterates over a stream of indices and checks for each index _1 that the distance of the current index and the next index of a[_1] is not more than a[_1].

How exactly does _1 work?

@KritixiLithos It's like _, but refers to the first pulled value. If I had used multiple _s, each would have pulled a separate value. For example, [1, 2, 3] | print(_, _, _) prints 123, but [1,2,3] | print(_, _1, _1) prints 111 222 333 (on separate lines).

Vyxal, 10 bytes
ƛ?=T¯‹≤A;A

Try it Online!
ƛ       ;A # Does every value have the property that...
       A   # All of...
    ¯      # The differences between...
 ?=T       # Indices of that value in the input
     ‹     # Minus 1
      ≤    # Are at most that value?

05AB1E, 13 bytes
Dì©v®¦©yky›_P

Try it online!
or as a Test suite
Explanation
Dì             # duplicate input and prepend the copy to the original
  ©            # store a copy in the register
   v           # for each element in the list
    ®          # push the list from register
     ¦©        # remove the first element and store a copy in the register
       yk      # get the index of the current element in the list
         y›_   # check if it's less than or equal to the current element
            P  # product of stack

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Return neighbors index in an 3x3 grid
Alright, my second attempt at a code golf, let's see how this goes.
Pretend you have a 3x3 grid of digits, from 0 to 8:
 0 | 1 | 2
---+---+---
 3 | 4 | 5
---+---+---
 6 | 7 | 8

Return the neighbors the input has as indexes of the array.
Rules:

It's code golf, so shortest answer wins.
The pretend array's index can start at 0 or 1. (all examples use 0 though)
The submission can be just a procedure/function/method, but an example would be nice
The returned value can be in any order (if the input is 0 you could output either 13 or 31)
If you want, the output can be a list of numbers, e.g. [0,4,6] instead of 046
Diagonals don't count, as shown by the examples.

Examples:
0 -> 13
3 -> 046
4 -> 1357

It looks like this challenge could benefit from some time in the Sandbox. You can post your challenge there so others can review it and help you out with it before posting it to main. From your examples I'm guessing you're not counting diagonals. You may want to add this to the question itself. You also mention the requirement to output the indexes of the array that are neighbors. I think this could just be hardcoded for a 3x3 grid. Would it maybe be better to output the neighbors themselves?

Just so you know, frowned upon isn't really something we do here; hardcoding the output is either allowed or it isn't. Since it's usually pretty hard to define what exactly counts as hardcoding, I'd personally just allow it or give the grid size as an additional input.

Can the output be a list of numbers, e.g. [0,4,6] instead of 046?

@Laikoni Yes, a little bit too late because you've already answered it.

@Dennis Yes, I wasn't quite sure how to put it. I like how the C and python answers did it, by providing both, but having the non-hard coded answer as the final. I wanted to encourage algorithms rather than hard-coding, but I wasn't sure if it was even possible (without overly long answers), and I didn't want to have no answers to my question.

Jelly, 16 13 bytes
9Ḷ,d3ạ/S€=1T’

Try it online!
How it works
9Ḷ,d3ạ/S€=1T’  Main link. Argument: n (0, ..., 8)

9              Set the return value to 9.
 Ḷ             Unlength; yield [0, ..., 8].
  ,            Pair; yield [[0, ..., 8], n].
   d3          Divmod 3; yield [[[0, 0], ..., [2, 2]], [n:3, n%3]]].
     ạ/        Reduce by absolute difference, yielding
               [[|0 - n:3|, |0 - n%3|], ..., [[|2 - n:3|, |2 - n%3|]].
       S€      Sum each, yielding
               [|0 - n:3| + |0 - n%3|, ..., [|2 - n:3| + |2 - n%3|].
         =1    Compare the sums with 1.
           T   Truth; yield all 1-based indices of 1.
            ’  Decrement to yield all 0-based indices of 1.

The rules state: "The pretend array's index can start at 0 or 1." - you can drop the Decrement at the end.

@steenbergh I assume I'd have to take 1-based input as well then, which costs as many bytes as it saves.

MATL, 17 16 bytes
9:qWIe1Y6Z+i)BPf

The array is 1-based, that is, contains numbers from 1 to 9.
Try it online! Or verify all test cases.
Explanation
Consider input 2 as an example.
9:q  % Push [0 1 2 ... 8]
     % STACK: [0 1 2 ... 8]
W    % Rise to 2, element-wise
     % STACK: [1 2 4 ... 256]
Ie   % Reshape as 3-row matrix (column-major order)
     % STACK: [1   8  64;
               2  16 128;
               4  32 256]
1Y6  % Push [0 1 0; 1 0 1; 0 1 0]
     % STACK: [1   8  64;
               2  16 128;
               4  32 256],
              [0   1   0;
               1   0   1;
               0   1   0]
Z+   % Convolution, maintaining size
     % STACK: [10  81 136;
               21 170 336;
               34 276 160]
i    % Take input, n
     % STACK: [10  81 136;
               21 170 336;
               34 276 160],
               2
 )   % Get n-th entry (1-based; column-major order)
     % STACK: 21
B    % Convert to binary
     % STACK: [1 0 1 0 1]
P    % Flip
     % STACK: [1 0 1 0 1]
f    % Find: gives indices of nonzeros. Implicitly display
     % STACK: [1 3 5]

Wat? How did you come up with this?

@RobertFraser These challenges about finding neighbours always suggest to me a convolution approach. But convolution inherently adds the neighbours' values, so I needed to be able to separate them at the end---that's the powers-of-two and binary expansion parts

Mathematica, 32 bytes
GridGraph@{3,3}~AdjacencyList~#&

Uses a graph instead of an array. GridGraph@{3,3} constructs a 3x3 grid-shaped graph, shown below, which Mathematica helpfully labels with the numbers 1–9 for the vertices by default. Then ~AdjacencyList~#& tells you the neighbours of a vertex.

Gotta love those builtins...

Mathematica, 40 bytes
{24,135,26,157,2468,359,48,579,68}[[#]]&

1-indexed. Just looks up the answer. Can someone do better in Mathematica?

I'm surprised that there isn't a builtin for this. Like I'd expect there to be a builtin to find all neighbors of an element in a 2D array, but I'm not sure, I don't know anything about Mathematica other than the fact that it has too many builtins.

You can save a byte by using 0-indexing and 31[420,51,...,75][[#]]&.

You can use GridGraph@{3,3}~AdjacencyList~#& for 32 bytes, with 1-indexing.

@lanlock4 Awesome! Please make that an answer so I can upvote it!

Octave, 42 40 39 bytes
@(n,x=~e(3),y=x(n)=1)find(bwdist(x)==1)

1-based index.
Verify all test cases.
Explanation:
x=~e(3);         % create a 3*3 matrix of zeros
x(n)=1;          % set the element with index n to 1
d=bwdist(x);     % compute the distance transform of the matrix
find(d == 1)     % find where the distance is 1.

Example: n = 2
x =

   0   0   0
   1   0   0
   0   0   0

(In Octave data is stored column-wise.)
d =

   1.00000   1.41421   2.23607
   0.00000   1.00000   2.00000
   1.00000   1.41421   2.23607

logical index where distance is 1:
d == 1

 1   0   0
 0   1   0
 1   0   0

find(d ==1)

 1
 3
 5

Python 2, 71 bytes
lambda n:filter(abs,[(n-3)*(n>3),(n+3)*(n<7),~-n*(n%3!=1),-~n*(n%3>0)])

1-indexed
Try it online!

Getting the result from a predefined list of  results is shorter (46 bytes):

[13,204,15,406,1357,248,37,468,57].__getitem__

0-indexed
Try it online!

Ruby, 51 48 45 bytes
->a{[a+3,a-3][a/6..a/3]+[a+1,a-1][a%-3..a%3]}

Try it online!
Create 2 arrays, with vertical and horizontal neighbours, then select one or more of them.
Ruby hardcoded, 44 bytes
->a{%w(13 024 15 046 1357 248 37 468 57)[a]}

... Not worth it.

Python 2, 51 bytes
lambda x:[x+3,x-3][x/6:x/3+1]+[x+1,x-1][x%-3:x%3+1]

Based on a previous version of my Ruby answer, I found it interesting because it was mostly the same code, using a different trick, and produces the same result. Getting this one right helped me golf the ruby answer a little more.
Basically, ruby has it shorter because the array slice index are inclusive, python needs a +1 to compensate.
Explanation
Get the 2 arrays (vertical and horizontal neighbours), then select one or both based on some calculations.

C, 100 92 91 83 78 74 bytes
p(n){putchar(n+48);}f(n){n>3&&p(n-3);n<7&&p(n+3);n%3&&p(n+1);--n%3&&p(n);}

1-indexed. Thanks to @Neil for saving 4 bytes.
Try it online!
Hardcoded version, 56 bytes
l[]={13,204,15,406,1357,248,37,468,57};
#define L(n)l[n]

0-indexed

In the first version, can you not write n>3&&p(n-3) etc. to save 4 bytes? In the second version, can you not write l[]= to save a byte?

Are you sure your code is currently correct? When I try the test cases it fails for all three.. :S Try it here. Could you perhaps provide a working TIO-link, perhaps I'm doing something wrong?

@KevinCruijssen TIO link added, and it seems that I forgot to edit the actual code on the last edit... Oh, well. Your link is working correctly too, but notice that my answer is 1-indexed whereas the example test cases are 0-indexed.

@Steadybox Ah, you're indeed right. I missed the 1-indexed part, my bad. Thanks for adding the TIO. +1

Haskell, 74 71 68 bytes
f n=[x|x<-[n-3,n-1..n+3],0<x,x<10,gcd 3x<2||n-1/=x,gcd 3n<2||n+1/=x]

Try it online! Uses a 1-indexed grid. Example usage: f 3 returns [2,6].
Edit: Saved 3 6 bytes thanks to Ørjan Johansen!

For 77 75 bytes, the following function # works for an arbitrary grid size m:
n#m=[x|x<-[n-m,n-1,n+1,n+m],0<x,x<=m*m,gcd x m<m||n-1/=x,gcd n m<m||n+1/=x]

Try it online!
For each n the list [n-m,n-1,n+1,n+m] contains all four neighbours. For each entry x in this list we check -1<x and x<m*m to make sure x is not above or below the grid, mod n 3>0||n-1/=x to enforce the left grid border and mod(n+1)m>0||n+1/=x for the left border.

You can use [n-3,n-1..n+3] and gcd 3n>1.

Oops, never mind that gcd part. It should have been <3, and then breaks for n==0. You might be able to use that trick if you change everything to 1-indexed.

Oh, and the n/=2&&n/=5 can be replaced by mod x 3>0. (Or the gcd version with reindexing, which might now be used twice.)

Java 7, 63 bytes (hardcoded)
int c(int i){return new int[]{31,420,51,640,7531,842,73,864,75}[i];}

0-indexed
(Reversed order output because 024 and 046 aren't valid integers.)
Still working on a non-hardcoded version, but I can assure you it won't be shorter..
Try it here.

82 bytes
String c(int n){return""+(n>3?n-3:"")+(n<7?n+3:"")+(n%3>0?n+1:"")+(--n%3>0?n:"");}

1-indexed
Based on @Steadybox' C answer
Try it here.

Vyxal 3, 9 bytes
kd⁻ṪÞo1⁾i

Try it Online!
kd⁻ṪÞo1⁾i
        i  # value of program at index of input
kd⁻Ṫ       # digits 0-8 in a 3x3 square
    Þo     # grid neighbors
      1⁾   # flatten by 1

Created with the help of Luminespire.

APL (Dyalog Classic), 34 bytes
⌷∘42 531 62 751 8642 953 84 975 86

1-indexed, hardcodes the values :(
Try it online!

JavaScript + lodash, 71 bytes
f=a=>_.range(9).filter(b=>a>b?f(b).includes(a):[,1,,1][b-a]&&b%3|a%3<2)

Batch, 116 bytes
@set c=cmd/cset/a%1
@set/ar=%1%%3
@if %1 gtr 2 %c%-3
@if %r% gtr 0 %c%-1
@if %r% lss 2 %c%+1
@if %1 lss 6 %c%+3

0-indexed.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
><> Out of Water
The beloved fish who swims through the code of ><> (an esoteric programming language) has been taken out of its natural environment. This change has rendered it incapable of moving around in the way it's used to: what used to be toroidal movement has been restricted to simple left-to-right movement. But ><> programs are still written as if the fish were capable of moving through them. It is your task, dear programmer, to write a program to linearize a ><> program. And do it in as few bytes as possible; fish don't have very large memories.
Movement in ><>
In ><>, movement is toroidal and one character at a time. This means that the fish (the pointer) can "wrap" around from the end of a line back to the beginning. In ><>, the fish also is capable of moving top-to-bottom, bottom-to-top, and right-to-left, in contrast to the way most pointers move. So this movement pattern would be valid:
>>>^  >>>v
   >>>^  v

and it would end on an infinite loop (looping back to the top line once it gets past the bottom infinitely).
The fish moves in a grid of length equal to  max(row length) and height equal to the number of rows.
How do you figure out which way the fish moves? These commands change the direction vector of movement (e.g. (-1,0) means right-to-left):
Command | Direction Change
---------------------------
   >    | (1,0) (default)
   <    | (-1,0)
   ^    | (0,1)
   v    | (0,-1)
   /    | (x,y) -> (y,x)
   \    | (x,y) -> (-y,-x)
   |    | (x,y) -> (-x,y)
   _    | (x,y) -> (x,-y)
   #    | (x,y) -> (-x,-y)
   ;    | (0,0)

As noted, the fish starts moving left-to-right, i.e. with direction vector (1,0). The fish starts parsing commands starting with the first command it sees and changes its direction if a command matches one of the aforementioned direction changers.
The fish stops moving when it sees a ; and terminates the program.
Input
Input will be a valid (e.g. not infinitely looping) program given through STDIN. You may also read a file if you wish. The lines of each program will not necessarily be of the same length.
Input is given as a string, with newlines separating each line in the program.
Programs will not loop, which also means they will always terminate with a ;.
Output
Output will be the program linearized. That is, you should return all of the characters (including direction changers) that the fish would see if it ran the program "normally." This is all of the characters in its path to the ;.
If the input is has lines of unequal length and the fish ends up moving along a line shorter than the length of the longest line, you should treat that as if the fish were moving over a space (see test cases).
Those familiar with ><> will know that direction changers are not the only way to do movement in it, but for simplicity's sake treat the input as if they are the only way to affect movement.
Rules

Standard loopholes apply
You may write either a full program or function
Input is supplied through STDIN or a file as a string containing the program lines separated by newlines (\n)

You may take the input differently, within reason (feel free to ask me if you have a specific kind of input in mind). You may not pad the input with spaces so the line lengths match.
Refer to this meta post regarding flexible input. As it stands of posting, general consensus is to be as flexible as possible within reason.

Output is a single string through STDOUT or returned by the function (depending on what you choose to do, see Rule 2)

Test Cases
v     >v
>abcv//;
gfed<^ih

v>abcv<defghi^//>v;

v     >v
>abcv//;
gfed<^

v>abcv<defg  ^//>v;

abcdef;

abcdef;

abcd|;

abcd|dcba;

abcd#;

abcd#dcba;

abcd\;
    _

abcd\_\dcba;

^;
>abcde/
 ^jihg<

^ >abcde/ <ghij^a;

;

;

Can we take the input as an array of strings?

Can we assume that the first character (the top left one) won't be a semicolon?

@KritixiLithos good question, I'm going to say you can't assume that. I'll add a test case.

@Luke you may take the input as an array of strings if it is either very hard or impossible to operate on the input format (string with lines separated by newlines). See the now-added Rule 3.

Is a leading space acceptable?

@HyperNeutrino In the output or input? Actually, I think I'm gonna say no to both.

Okay, alright. I originally wanted to have a leading space in the output, but that is stretching the rules quite a bit.

Can we assume the input will not have null bytes in it?

Will we have a case where momentum is down or up and we come across a |?  What about left/right and we come across a _?

@NotthatCharles The instructions explain what happens in those cases "|     (x,y) -> (-x,y),
_   (x,y) -> (x,-y)"

Obligatory upvote for absurd rationale

@MistahFiggins I'll say you can assume that. I don't see why null bytes would be used in ><> (they would likely throw an error). For sake of tidying the comments section I'm deleting my previous comment.

@fəˈnɛtɪk I wanted to make sure it was correct.

@Cole It takes 13 chars (so 7%) to convert a newline-separated string to an array. Is that "very hard to operate on" the newline input?

@NotthatCharles You may take input however you wish within reason, so long as you don't prepad with spaces. So yes, an array of strings (or 2D array of chars) is acceptable per the input spec.

Ok, great, thanks.  That changed before I posted my comment, but I had not refreshed the page.

Röda, 405 393 392 391 371 366 361 236 234 232 230 223 200 bytes
F f{L=f()|[#_]|sort|tail
c=""x=0
y=0
X=1
Y=0{l=f[y]l.=[" "]*(L-#l)c=l[x]a=X
[c]
C=indexOf(c,`><v^/\|_#`)X=[1,-1,0,0,-Y,Y,-X,X,-X,X][C]Y=[0,0,1,-1,-a,a,Y,-Y,-Y,Y][C]x+=X
x=x%L
y+=Y
y=y%#f}until[c=";"]}

Try it online!
Check outputs!
Explanation (outdated)
F f{                          /* Declares a function F with parameter f */
                              /* Takes a 2D array of single-char Strings as f */
L =                           /* L contains the value of the length of the longest line*/
    f()                       /* Push the contents each element of f to the stream; this pushes each line*/
        | [#_]                /* Pull a line and push its length to the stream*/
               |sort|tail     /* Sort it and get the last value (the largest one) */
c=""                          /* c contains the value of the current char that is being processed */
x=0; y=0                      /* x and y contain the position of the fish */
X=1; Y=0                      /* X and Y contain the direction of the fish */
{ ... }while [c != ";"]       /* While c is not `;` do: */
l=f[y]                        /*  l is the line (row) the fish is at */
c=" " if [x >= #l]            /*  If x is more than or equal to the line's length, set c to a space (so that we don't need to pad spaces to the array at the beginning)*/
else c = l[x]                 /*  Else set c to the character a position x of l*/
[c]                           /*  Push c to the output stream; ie prints c without a trailing newline*/
a = X                         /*  a preserves the value of X before analysing c */
C = indexOf(c,`><v^/\|_#`)    /*  Simple enough */
X=[1,-1,0,0,-Y,Y,-X,X,-X,X][C]/*  Map each value of C to their respective X-direction in the array */
                              /*  If c cannot be found in `><v^/\|_#` then it will be given the value of -1, or in other words, the -1th element of an array its last element */
Y=[0,0,1,-1,-a,a,Y,-Y,-Y,Y][C]/*  Do the same thing for Y */
x += X                        /*  Change the x-pos by the X-direction */
x = x%L                       /*  Wrap around the right edge */
y += Y                        /*  Do the same for y */
y=y%#f                        /*  But wrap around the bottom instead */
x+=L if[x<0]                  /*  Wrap around the left */
y+=#f if[y<0]                 /*  Wrap around the top */
}

Edits

10 bytes saved thanks to @fergusq by using % instead of checking whether x or y is over the boundaries, which paved the way for 2 more!
Used `\` instead of "\\"
Moved c="" to the second line and then removed the newline following it
Moved the conversion of the lines to single-character array into the loops instead of at the beginning (inspired by the Python answer)
Used the brace syntax of while (thanks to @fergusq for spotting that)
Moved the a=X out of the if-statements
Thanks to @fergusq for finding a shorter way to find the length of the longest line
Used array syntax instead of if-statements (like the Python answer) to save tons of bytes
Removed the code that padded spaces, instead spaces are added as the ><> moves along
Fixed a bug thanks and golfed one character thanks to @fergusq
Removed the +1 at the end of indexOf and restructured code to save 2 bytes
Saved 2 bytes by moving things around (thanks to @fergusq again)
Saved 1 byte thanks to @fergusq by using a different method of padding spaces
Saved 1 byte by using until[c=";"] instead of while[c!=";"]
Thanks to a hint from @fergusq, I removed the loop that pads spaces and replaced it with l.=[" "]*L
Saved over 20 bytes by removing the if-statements at the end that wrap the program around the left and top edges

I think you can save a few bytes by using x=((x+X)%#l) instead of x+=X. Unfortunately, (-1)%#l still returns -1.

@fergusq Golfed your suggestion :)

You can use it with y too: y=y%#f.

@fergusq Was just about to add that :)

I thought about this more, here are two other golfing tips: use key instead of cmp and use {...}while[...] instead of while[...]do ... done.

oh wow my answer gave you an idea which ended up beating my answer ;_; well done, +1 :P

Your turn, Röda. :)

Can you use l+=" "until[x<#l];c=l[x] at the fifth line?

@fergusq Seems to work. Thanks, it saves 1 byte :) And I found out that using until[c=";"] is shorter than while[c!=";"]

Python 2, 262 243 237 235 234 233 231 221 219 218 217 bytes
Takes input as ['<line_1>', '<line_2>', ...]
i=input()
q=max(map(len,i))
i=[k+' '*q for k in i]
x=y=k=0
j=1
o=''
while';'not in o:r=[1,-1,-j,-k,0,0];o+=i[y][x];l='><#\\v^/|_'.find(o[-1]);a=(r+[k,-j,j])[l];k=([k,-k,k,j]+r)[~l];j=a;x=(x+j)%q;y=(y-k)%len(i)
print o

Try it Online!
-19 bytes thanks to @math_junkie
-6 bytes thanks to @ThisGuy
-2 bytes by extracting max(map(L,i)) to a variable (because it is theoretically used twice).
-1 byte by reducing the number of times i[y][x] shows up.
-1 byte by using '\x00' so I don't have to do the [1:] part of o[1:] in the output
-2 bytes by using \0 instead of \x00
-10 bytes thanks to @KritixiLithos for realizing that I can pad as much as I want on the right side because the extra will be ignored
(no byte change) fixed bug because extracted variable was outside of loop
-2 bytes because now I only use len 2 times so reassigning it takes 2 additional bytes
-2 byte by using while';'not in o instead of while o[-1]!=';', and using o='' instead of o='\0'. This not only saves 2 bytes but also gets rid of the leading null byte which was technically not really valid.
Explanation
i = input()                       # Takes input as an array of strings
q = max(map(len,i))               # Finds the width of the longest line
i = [k + ' ' * q for k in i]      # Makes sure everything is at least that width
x = y = k = 0                     # Set the point to (0, 0). Set the vertical motion to 0
j = 1                             # Set the horizontal motion to 1
o = '\0'                          # Initialize the output to a null byte (this is output as nothing, so it doesn't actually affect output)
while o[-1] != ';':               # While the last character in the output is not ';' (this is why the output needs to be initialized with something, otherwise o[-1] gives an index error)
    r = [1,-1,-j,-k,0,0]          # Some of the vertical and horizontal coordinates correspond in opposite order
    o += i[y][x]                  # Add the current character to the output
    l = '><#\\v^/|_'.find(o[-1])  # Find the index of the current character here (or -1 if it's just a regular character)
    a = (r + [k, -j, j])[l]       # The fancy array contains the horizontal movement for each control character
    k = ([k, -k, k, j] + r)[~l]   # The fancy array contains the vertical movement for each control character. Using ~l to get the right index, because r has the values backwards
    j = a                         # a was a placeholder because otherwise k would not be correct
    x = (x + j) % q               # Adjust the pointer position
    y = (y - k) % len(i)          # Adjust the pointer position
print o                           # Print the output after the loop is finished

You can golf off the try since find returns -1 if not found : TIO

You can assign len to a variable e.g L to save 3 bytes and another 4 by changing the multiline assignment to 0 into 1 line x=y=k=0.

@Cole In my suggeted golf, I added j and k to the end of each array. This is so the direction is maintained

I'm counting 237 bytes

@FelipeNardiBatista Mhm, so am I. Sorry, I failed at counting saved bytes.

Your move, Python :)

@KritixiLithos :) -1 byte, tied with you... oh wait you cut 2 bytes again. ;_;

Check the leaderboard again :)

@KritixiLithos Check again. :)

I don't see any change in the leaderboard... :P

You can get to 225 bytes by using q instead of q-L(k) in the 4th line. Try it online! (you should remove the \ in \\0)

@KritixiLithos That's actually 221 bytes now. Thank you very much! :)

Ruby, 274 200 187 183
Shaved off just a few more characters by dropping the momentum array, d.
I'm pretty proud of this one.  This was fun!
It takes in an array of strings and returns the proper string.
->a{o,x,y='',-1,0
b,m=1,0
(o+=n=a[y=(y+m)%a.size][x=(x+b)%(a.map &:size).max]||' '
b,m=([1]+[0,-1,0]*2+[1,-m]+[-b,m,b]*2+[-m,-b,-m,b,m])[2*('><^v/\\|_#'.index(n)||9),2])until o[?;]
o}

Commented below.
->a{
    o,x,y='',-1,0  # o is the output string, x and y are the positions in the array
    b,m=1,0          # b and m are the direction of momentum
    until o[?;] # until o contains a semicolon
        w=(a.map &:size).max # w is the max width of the arrays
        h=a.size    # h is the height of arrays
        x=x+b % w   # increment cursor position
        y=y+m % h
        o+=n=a[y][x]||' ' # add the new char (or " ") to o
        ix=2*('><^v/\\|_#'.index(n)||9) # find the index new char in the string
        b,m=([1]+[0,-1,0]*2+[1,-m]+[-b,m,b]*2+[-m,-b,-m,b,m])[ix,2] # set momentum to its new value
    end
    o # return output string
}

APL (Dyalog Unicode), 107 106 bytes
{v←⍬⋄d←⍳2⋄v⊣⍵{v,←c←⍵⌷⍺⋄(⍴⍺)|⍵+d⊢←('^<v>/\|_#'⍳c)⊃⌽d(-d)(-@0⊢d)(-@1⊢d)(⌽d)(-⌽d),(⊢,-)(⊂,⊂∘⌽)⍳2}⍣{';'∊v}0 0}

Try it online!
Takes a character matrix as input. The code uses the technique already used here to select the next direction based on the current command. Direction change for ; is not handled because we'll stop once it is reached anyway.
How it works
{ ⍝ Input: the ><> program as a matrix
  v←⍬   ⍝ List of commands walked over
  d←⍳2  ⍝ Initial direction (0 1); (vertical horizontal)
  v⊣⍵{  ⍝ Return the resulting v after running...

    ⍝ Extract the current command c and append to v
    v,←c←⍵⌷⍺
    ⍝ Update the direction based on the command
    ⍝ (0 1) is east, (0 ¯1) west, (1 0) south, (¯1 0) north
    ⍝ - mirrors in each direction, ⌽ swaps the two (mirror by \)
    ⍝ @0 or @1 selects which element to apply the transformation
    ⍝ (⊢,-)(⊂,⊂∘⌽)⍳2 evaluates to (0 1)(1 0)(0 ¯1)(¯1 0), the directions for >v<^
    d⊢←(⌽d(-d)(-@0⊢d)(-@1⊢d)(⌽d)(-⌽d),(⊢,-)(⊂,⊂∘⌽)⍳2)⊃⍨'^<v>/\|_#'⍳c
    ⍝ Add the step to the coordinates and handle wrapping
    (⍴⍺)|⍵+d
  }⍣{';'∊v}0 0  ⍝ Start at (0 0) and repeat until v contains ';'
}

PHP 7, 291 260 bytes
for($m=max(array_map(strlen,$z=explode("
",$argv[1]))),$y=0,$r=count($z)-$v=1;';'!=$c;[$v,$w]=[[$v,1,-1,0,0,-$w,$w,-$v,$v,-$v][$o=strpos(' ><^v/\|_#',$c)],[$w,0,0,-1,1,-$v,$v,$w,-$w,-$w][$o]],$x+=$m+$v,$x%=$m,$y=0<=($y+=$w)?$r<$y?:$y:$r)echo$c=$z[$y][$x]??' ';

I count 291 bytes/chars.

You're correct, I fail at counting apparently =P

Hah Don't worry, I did that too.

I found some things to golf, taking this down by 25% to 218 bytes. Not tested, but definitely worth a look.

a flaw in one of my golfings and six more bytes golfed: updated golfing list.

That's quite a big improvement, I'll look into it later :) The challenge specifically requires input as a single string with newlines though, unless "it is either very hard or impossible to operate on the input format". I don't think that is the case here.

I have applied your tips, as far as possible while keeping a string input.

you can save many chars if you take in the string as an array.  The specs were changed.

JavaScript, 242 236 235 231 220 bytes
a=>{n=a.length;m=x=y=p=0;a.map(g=>m=(w=g.length)<m?m:w);q=1,o="";while((t=a[y][x]||" ")!=";")o+=t,h=q,q=[q,1,0,p,-q][(s=">v\\| <^/_#".indexOf(t)+1)%5]*(r=s>5?-1:1),p=[p,0,1,h,p][s%5]*r,x=(x+q+m)%m,y=(y+p+n)%n;return o+t}

Try it online!

you can save 13 char if you take in the string as an array.  The specs were changed.


text:
Suggest me a challenge!
I am too bored and want a challenge to solve. But I do not see any interesting challenges, and I am too lazy to search for one. Can you (Well, technically your code) suggest me one?

I/O
Input: None.
Output: A link to a random open(i.e. non-closed) challenge("Challenge" excludes tips!) on PPCG. You may not link to an answer in a challenge, Just a challenge. (I didn't ask for an interesting answer!)

Examples
Valid:
http://codegolf.stackexchange.com/questions/93288/make-me-a-mooncake
http://codegolf.stackexchange.com/questions/113796/raise-a-single-number
http://codegolf.stackexchange.com/questions/113898

Invalid:
http://codegolf.stackexchange.com/questions/78152/tips-for-golfing-in-matl (tips question)
http://codegolf.stackexchange.com/questions/113896/josephus-problem (closed)
http://codegolf.stackexchange.com/questions/84260/add-two-numbers/84365#84365 (linked to answer)

Can we output http://codegolf.stackexchange.com/questions/93288/ instead of http://codegolf.stackexchange.com/questions/93288/make-me-a-mooncake (note the lack of challenge name).

@Kritixi Lithos Sure, that works.

Not all tips questions have the word "tips" in their name. See this one for example. Is that allowed or did you mean to remove challenges in the "tips" tag?

@seshoumara The latter, that's also the reason I typed 'tips' as a tag.

There are about 6k questions fulfilling your criteria on PPCG. Do all need to have a chance of being picked by random, or can I pick at random from the first 50 results I get from a search link?

@seshoumara the former option.

@SIGSEGV I believe there is no way to choose a random question from every open question asked.

@Okx Use your brain.. (Hint: every question and answer has an unique id)

Thanks. Also, can we only give [tag:code-golf] questions? The SE API needs either a tagged parameter or an intitle parameter.

@Okx Huh? I do not understand what you mean. I believe you can put newlines in code-golf too.

@SIGSEGV I mean questions with the tag [tag:code-golf]

@Okx you could generate the post id first, then see if it's valid. That way your problem is solved.

Let us continue this discussion in chat.

I am going to answer with SEDE!

@DownChristopher Sure, Why not!

Actually one problem is it won't be a url but a id for the question. Would that be invalid? (I think so)

These people who don't answer all latest questions, and then say they're bored... Did you write an answer for every new question posted? You seem to only have written 17 answers.

JavaScript (ES6), 209 bytes
Does work, but will most likely hit the StackExchange API limit very quickly. It will probably take a while to output the link, as it's checking randomly for a valid question.
_=>fetch(`//api.stackexchange.com/2.2/questions/${new Date%2e4}?site=codegolf`).then(_=>_.json()).then((a,b=a.items)=>{if(!b.length||b[0].tags.includes`tips`||b[0].closed_date)f();else console.log(b[0].link)})

f=_=>fetch(`//api.stackexchange.com/2.2/questions/${new Date%2e4}?site=codegolf`).then(_=>_.json()).then((a,b=a.items)=>{if(!b.length||b[0].tags.includes`tips`||b[0].closed_date)f();else console.log(b[0].link)})

f();

The OP said that all questions fitting the requirements need to have a chance of being chosen at random.

@seshoumara should be fixed now.

Save 4 bytes by dropping the API version from the URL.

Got https://codegolf.stackexchange.com/questions/173/tips-for-code-golfing-in-c which is not valid

Can confirm that this generates [tag:tips] challenges too...

Python 3, 452 339 bytes
from requests import*
from random import*
while 1:
    n=randrange(999999)
    r=get("http://api.stackexchange.com/questions/%d?site=codegolf"%n).json()
    if r["items"]:
        m=r["items"][0]
        if "tips" not in m["tags"]:
            try:m["closed_date"]
            except:print("http://codegolf.stackexchange.com/q/%d"%n);break

A bit unsightly and not very golf-y, but I couldn't figure out a better way to do it. Since this more or less brute-forces the API, you'll spend up your quota quite quickly and start getting errors, but after a few hours it'll work again.
EDIT: Saved 113 bytes by removing multiple unnecessary things, thanks to NoOneIsHere.

You only use l once, so it is unnecessary.

That's correct. I did that so I could print the link afterwards if it was valid, but that printed the API link instead of the normal one. Thanks for reminding me.

Also, you can online the try and maybe the except.

That is also correct. Thanks again.

Glad to help.  Pad

SEDE SQL: 79 bytes
Select Id from posts where ClosedDate IS NULL AND Tags !='tips' ORDER BY RAND()

There are 2 catches. One you have to wait for a while before running again or you have a cache hit (as a mod told me) and you only get the question id number.

I think it is valid because I am not that lazy to not even being able to type

Yes! Your word is lay on your challenge