This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
}:_:<:1:+%<:a:~$^:_:

View file

@ -0,0 +1,5 @@
Create a program that, when run, would display all integers from 1 to ∞ (or any relevant implementation limit), in sequence (i.e. 1, 2, 3, 4, etc) if given enough time.
An example may not be able to reach arbitrarily-large numbers based on implementations limits. For example, if integers are represented as a 32-bit unsigned value with 0 as the smallest representable value, the largest representable value would be 4,294,967,295. Some languages support arbitrarily-large numbers as a built-in feature, while others make use of a module or library.
If appropriate, provide an example which reflect the language implementation's common built-in limits as well as an example which supports arbitrarily large numbers, and describe the nature of such limitations—or lack thereof.

View file

@ -0,0 +1,6 @@
main:
(
FOR i DO
printf(($g(0)","$,i))
OD
)

View file

@ -0,0 +1,4 @@
BEGIN {
for( i=0; i != i + 1; i++ )
print( i )
}

View file

@ -0,0 +1,9 @@
with Ada.Text_IO;
procedure Integers is
Value : Integer := 1;
begin
loop
Ada.Text_IO.Put_Line (Integer'Image (Value));
Value := Value + 1;
end loop;
end Integers;

View file

@ -0,0 +1,7 @@
with Ada.Text_IO;
procedure Positives is
begin
for Value in Positive'Range loop
Ada.Text_IO.Put_Line (Positive'Image (Value));
end loop;
end Positives;

View file

@ -0,0 +1,2 @@
10 I% = 0
20 PRINT I%: IF I% < 32767 THEN I% = I% + 1: GOTO 20

View file

@ -0,0 +1,3 @@
x=0
Loop
TrayTip, Count, % ++x

View file

@ -0,0 +1,4 @@
10 LET A = 0
20 LET A = A + 1
30 PRINT A
40 GO TO 20

View file

@ -0,0 +1,2 @@
A = 0
DO: A = A + 1: PRINT A: LOOP 1

View file

@ -0,0 +1,5 @@
*FLOAT 64
REPEAT
i += 1
PRINT TAB(0,0) i;
UNTIL FALSE

View file

@ -0,0 +1,9 @@
INSTALL @lib$+"HIMELIB"
PROC_himeinit("")
reg% = 1
PROC_hiputdec(reg%, "0")
REPEAT
SYS `hi_Incr`, ^reg%, ^reg%
PRINT TAB(0,0) FN_higetdec(reg%);
UNTIL FALSE

View file

@ -0,0 +1 @@
0:?n&whl'out$(1+!n:?n)

View file

@ -0,0 +1,4 @@
++++++++++>>>+[[->>+<[+>->+<<---------------------------------------
-------------------[>>-<++++++++++<[+>-<]]>[-<+>]<++++++++++++++++++
++++++++++++++++++++++++++++++>]<[<]>>[-<+++++++++++++++++++++++++++
++++++++++++++++++++++>]>]>[>>>]<<<[.<<<]<.>>>+]

View file

@ -0,0 +1,4 @@
++++++++++>>-[>+[->>+<[+>->+<<--------------------------------------
--------------------[>>-<++++++++++<[+>-<]]>[-<+>]<+++++++++++++++++
+++++++++++++++++++++++++++++++>]<[<]>>[-<++++++++++++++++++++++++++
+++++++++++++++++++++++>]>]>[>>>]<<<[.<<<]<.>>-]

View file

@ -0,0 +1,6 @@
i = 1
loop {
p i
i = i + 1
}

View file

@ -0,0 +1 @@
1R@

View file

@ -0,0 +1,11 @@
#include <iostream>
#include <cstdint>
int main()
{
uint32_t i = 0;
while(true)
std::cout << ++i << std::endl;
return 0;
}

View file

@ -0,0 +1,9 @@
#include <stdio.h>
int main()
{
unsigned int i = 0;
while (++i) printf("%u\n", i);
return 0;
}

View file

@ -0,0 +1,14 @@
#include <gmp.h>
int main()
{
mpz_t i;
mpz_init(i); /* zero now */
while (1) {
mpz_add_ui(i, i, 1); /* i = i + 1 */
gmp_printf("%Zd\n", i);
}
return 0;
}

View file

@ -0,0 +1,29 @@
#include <openssl/bn.h> /* BN_*() */
#include <openssl/err.h> /* ERR_*() */
#include <stdio.h> /* fprintf(), puts() */
void
fail(const char *message)
{
fprintf(stderr, "%s: error 0x%08lx\n", ERR_get_error());
exit(1);
}
int
main()
{
BIGNUM i;
char *s;
BN_init(&i);
for (;;) {
if (BN_add_word(&i, 1) == 0)
fail("BN_add_word");
s = BN_bn2dec(&i);
if (s == NULL)
fail("BN_bn2dec");
puts(s);
OPENSSL_free(s);
}
/* NOTREACHED */
}

View file

@ -0,0 +1,5 @@
module IntegerSequence
import StdEnv
Start = [x \\ x <- [1..]]

View file

@ -0,0 +1 @@
(map println (next (range)))

View file

@ -0,0 +1,35 @@
# This very limited BCD-based collection of functions
# makes it easy to count very large numbers. All arrays
# start off with the ones columns in position zero.
# Using arrays of decimal-based digits to model integers
# doesn't make much sense for most tasks, but if you
# want to keep counting forever, this does the trick.
BcdInteger =
from_string: (s) ->
arr = []
for c in s
arr.unshift parseInt(c)
arr
render: (arr) ->
s = ''
for elem in arr
s = elem.toString() + s
s
succ: (arr) ->
arr = (elem for elem in arr)
i = 0
while arr[i] == 9
arr[i] = 0
i += 1
arr[i] ||= 0
arr[i] += 1
arr
# To start counting from 1, change the next line!
big_int = BcdInteger.from_string "199999999999999999999999999999999999999999999999999999"
while true
console.log BcdInteger.render big_int
big_int = BcdInteger.succ big_int

View file

@ -0,0 +1,6 @@
> coffee foo.coffee | head -5
199999999999999999999999999999999999999999999999999999
200000000000000000000000000000000000000000000000000000
200000000000000000000000000000000000000000000000000001
200000000000000000000000000000000000000000000000000002
200000000000000000000000000000000000000000000000000003

View file

@ -0,0 +1 @@
(loop for i from 1 do (print i))

View file

@ -0,0 +1,2 @@
(defun pp (x) (pp (1+ (print x))))
(funcall (compile 'pp) 1) ; it's less likely interpreted mode will eliminate tails

View file

@ -0,0 +1,7 @@
import std.stdio, std.bigint;
void main() {
BigInt i;
while (true)
writeln(++i);
}

View file

@ -0,0 +1,36 @@
import std.stdio, std.traits, std.bigint, std.string;
void integerSequence(T)() if (isIntegral!T || is(T == BigInt)) {
T now = 1;
T max = 0;
static if (!is(T == BigInt))
max = T.max;
do
write(now, " ");
while (now++ != max);
writeln("\nDone!");
}
void main() {
writeln("How much time do you have?");
writeln(" 0. I'm in hurry.");
writeln(" 1. I've some time.");
writeln(" 2. I'm on vacation.");
writeln(" 3. I'm unemployed...");
writeln(" 4. I'm immortal!");
write("Enter 0-4 or nothing to quit: ");
string answer;
readf("%s\n", &answer);
switch (answer.toLower()) {
case "0": integerSequence!ubyte(); break;
case "1": integerSequence!short(); break;
case "2": integerSequence!uint(); break;
case "3": integerSequence!long(); break;
case "4": integerSequence!BigInt(); break;
default: writeln("\nBye bye!"); break;
}
}

View file

@ -0,0 +1,4 @@
var i: Integer;
for i:=1 to High(i) do
PrintLn(i);

View file

@ -0,0 +1 @@
1[p1+lpx]dspx

View file

@ -0,0 +1,10 @@
program IntegerSequence;
{$APPTYPE CONSOLE}
var
i: Integer;
begin
for i := 1 to High(i) do
WriteLn(i);
end.

View file

@ -0,0 +1 @@
for i in int > 0 { println(i) }

View file

@ -0,0 +1,22 @@
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
make
-- Run application.
do
from
number := 0
until
number = number.max_value
loop
print(number)
print(", ")
number := number + 1
end
end
number:INTEGER_64
end

View file

@ -0,0 +1,2 @@
(dotimes (i most-positive-fixnum)
(message "%d" (1+ i)))

View file

@ -0,0 +1 @@
F = fun(FF, I) -> io:format("~p~n", [I]), FF(FF, I + 1) end, F(F,0).

View file

@ -0,0 +1,6 @@
integer i
i = 0
while 1 do
? i
i += 1
end while

View file

@ -0,0 +1,2 @@
USE: lists.lazy
1 lfrom [ . ] leach

View file

@ -0,0 +1,12 @@
class Main
{
public static Void main()
{
i := 1
while (true)
{
echo (i)
i += 1
}
}
}

View file

@ -0,0 +1,2 @@
0>:n1+v
^o" "<

View file

@ -0,0 +1,2 @@
: ints ( -- )
0 begin 1+ dup cr u. dup -1 = until drop ;

View file

@ -0,0 +1,13 @@
program Intseq
implicit none
integer, parameter :: i64 = selected_int_kind(18)
integer(i64) :: n = 1
! n is declared as a 64 bit signed integer so the program will display up to
! 9223372036854775807 before overflowing to -9223372036854775808
do
print*, n
n = n + 1
end do
end program

View file

@ -0,0 +1,11 @@
InfiniteLoop := function()
local n;
n := 1;
while true do
Display(n);
n := n + 1;
od;
end;
# Prepare some coffee
InfiniteLoop();

View file

@ -0,0 +1,6 @@
Start,Programs,Accessories,Calculator,
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals],
Button:[plus],Button:1,Button:[equals],Button:[plus],Button:1,Button:[equals]

View file

@ -0,0 +1,9 @@
package main
import "fmt"
func main() {
for i := 1;; i++ {
fmt.Println(i)
}
}

View file

@ -0,0 +1,13 @@
package main
import (
"big"
"fmt"
)
func main() {
one := big.NewInt(1)
for i := big.NewInt(1);; i.Add(i, one) {
fmt.Println(i)
}
}

View file

@ -0,0 +1,8 @@
// 32-bit 2's-complement signed integer (int/Integer)
for (def i = 1; i > 0; i++) { println i }
// 64-bit 2's-complement signed integer (long/Long)
for (def i = 1L; i > 0; i+=1L) { println i }
// Arbitrarily-long binary signed integer (BigInteger)
for (def i = 1g; ; i+=1g) { println i }

View file

@ -0,0 +1 @@
mapM_ print [1..]

View file

@ -0,0 +1 @@
putStr $ unlines $ map show [1..]

View file

@ -0,0 +1,3 @@
procedure main()
every write(seq(1)) # the most concise way
end

View file

@ -0,0 +1 @@
count=: (smoutput ] >:)^:_

View file

@ -0,0 +1 @@
count=: (smoutput ] >:)@x:^:_

View file

@ -0,0 +1,5 @@
public class Count{
public static void main(String[] args){
for(long i = 1; ;i++) System.out.println(i);
}
}

View file

@ -0,0 +1,7 @@
import java.math.BigInteger;
public class Count{
public static void main(String[] args){
for(BigInteger i = BigInteger.ONE; ;i = i.add(BigInteger.ONE)) System.out.println(i);
}
}

View file

@ -0,0 +1,4 @@
var i = 0;
while (true)
document.write(++i + ' ');

View file

@ -0,0 +1 @@
1 [0 >] [dup put succ] while pop.

View file

@ -0,0 +1 @@
{`0:"\n",$x+:1;x}/1

View file

@ -0,0 +1 @@
i:0; while[1;`0:"\n",$i+:1]

View file

@ -0,0 +1 @@
0 do dup . 1 + loop

View file

@ -0,0 +1,6 @@
while 1
i=i+1
locate 1,1
print i
scan
wend

View file

@ -0,0 +1,10 @@
i = 1
-- in the event that the number inadvertently wraps around,
-- stop looping - this is unlikely with Lua's default underlying
-- number type (double), but on platform without double
-- the C type used for numbers can be changed
while i > 0 do
print( i )
i = i + 1
end

View file

@ -0,0 +1 @@
a = 1; while (1) printf('%i\n',a); a=a+1; end;

View file

@ -0,0 +1 @@
a = uint64(1); while (1) printf('%i\n',a); a=a+1; end;

View file

@ -0,0 +1 @@
N = 2^30; printf('%d\n', 1:N);

View file

@ -0,0 +1,11 @@
MCSKIP "WITH" NL
"" Integer sequence
"" Will overflow when it reaches implementation-defined signed integer limit
MCSKIP MT,<>
MCINS %.
MCDEF DEMO WITHS NL AS <MCSET T1=1
%L1.%T1.
MCSET T1=T1+1
MCGO L1
>
DEMO

View file

@ -0,0 +1,2 @@
x = 1;
Monitor[While[True, x++], x]

View file

@ -0,0 +1 @@
for i do disp(i);

View file

@ -0,0 +1,2 @@
my $i = 0;
print ++$i, "\n" while 1;

View file

@ -0,0 +1,2 @@
(for (I 1 T (inc I))
(printsp I) )

View file

@ -0,0 +1,4 @@
loop(I) :-
writeln(I),
I1 is I+1,
loop(I1).

View file

@ -0,0 +1,5 @@
:- use_module(library(chr)).
:- chr_constraint loop/1.
loop(N) <=> writeln(N), N1 is N+1, loop(N1).

View file

@ -0,0 +1,4 @@
i=1
while i:
print(i)
i += 1

View file

@ -0,0 +1,4 @@
from itertools import count
for i in count():
print(i)

View file

@ -0,0 +1,48 @@
/*count all the protons, electrons, & whatnot in the universe, and then */
/*keep counting. According to some pundits in-the-know, one version of */
/*the big-bang theory is that the universe will collapse back to where */
/*it started, and this computer program will be still counting. */
/*┌────────────────────────────────────────────────────────────────────┐
Count all the protons (and electrons!) in the universe, and then
keep counting. According to some pundits in-the-know, one version
of the big-bang theory is that the universe will collapse back to
where it started, and this computer program will still be counting.
According to Sir Author Eddington in 1938 at his Tamer Lecture at
Trinity Collecge (Cambridge), he postulated that there are exactly
136 2^245
protons in the universe and the same number of electrons, which is
equal to around 1.57477e+79.
Although, a modern extimate is around 10^80.
One estimate of the age of the universe is 13.7 billion years,
or 4.32e+17 seconds. This'll be a piece of cake.
*/
numeric digits 1000000000 /*just in case the universe slows down. */
/*this version of a DO loop increments J*/
do j=1 /*Sir Eddington's number, then a googol.*/
say j /*first, destroy some electrons. */
end
say 42 /*(see below for explanation of 42.) */
exit
/*This REXX program (as it will be limited to the NUMERIC DIGITS above, */
/*will only count up to 1000000000000000000000000000000000000000000... */
/*000000000000000000000000000000000000000000000000000000000000000000000 */
/* ... for another (almost) one billion more zeroes (then subtract 1).*/
/*if we can count 1,000 times faster than the fastest PeeCee, and we */
/*started at the moment of the big-bang, we'd be at only 1.72e+28, so */
/*we still have a little ways to go, eh? */
/*To clarify, we'd be 28 zeroes into a million zeroes. If PC's get */
/*1,000 times faster again, that would be 31 zeroes into a million. */
/*It only took Deep Thought 7.5 million years to come up with the */
/*answer to everything (and it double-checked the answer). It was 42.*/

View file

@ -0,0 +1,3 @@
#lang racket
(for ([i (in-naturals)]) (display (~a i "\n")))

View file

@ -0,0 +1,2 @@
i = 0
puts(i += 1) while true

View file

@ -0,0 +1 @@
Stream from 1 foreach println

View file

@ -0,0 +1,3 @@
(let loop ((i 1))
(display i) (newline)
(loop (+ 1 i)))

View file

@ -0,0 +1,5 @@
i := 0.
[
Stdout print:i; cr.
i := i + 1
] loop

View file

@ -0,0 +1,2 @@
package require Tcl 8.5
while true {puts [incr i]}