Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Count to 10

Name: Anonymous 2010-06-17 15:14

Lets see if /prog/ can count to 10 in C. I'll start:

int main(void){

Name: Anonymous 2010-06-17 20:16

(do-ec (: i 1 11) (display i))

Name: Anonymous 2010-06-17 20:34

>>39
True, too bad you arn't the Dalai Lama.

Name: Anonymous 2010-06-17 20:42

lisp code considered harmful

Name: Anonymous 2010-06-17 21:14

>>40
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

etc.

Name: Anonymous 2010-06-17 21:21


10 a = 0
20 a = a + 1
20 print a
40 if a = 10 then goto 60
50 goto 20
60 end

Name: Anonymous 2010-06-17 21:43

>>45
goto considered harmful

Name: Anonymous 2010-06-17 22:52

>>46
goto considered awesome.
the advice against it is like a giant trolling campaign to ensure that this brilliant feature is used only by those who can properly use it (and can think critically about complex ideas)
only EXPERT ENTERPRISE SOFTWARE ENGINEERS can use it properly, so don't even try.

Name: Anonymous 2010-06-17 22:56

>>46
10 a = 0
20 a = a + 1
30 print a
40 if a = 10 then gosub 60
50 gosub 20
60 end

Name: Anonymous 2010-06-17 23:35

>1+::.v
| -,:a<
@

cough

Name: Anonymous 2010-06-17 23:46

<,a._@#-b:::+1
How about a one-liner?

Name: Anonymous 2010-06-17 23:49

++++++[>++++++++<-]>
+.>++++++++++.<
+.>.<
+.>.<
+.>.<
+.>.<
+.>.<
+.>.<
+.>.<
+.>.<
--------.-.>.

Name: Anonymous 2010-06-17 23:54

>>51
You could easily eliminate all but one of those +.>.<s. And you could even use code tags!

Name: Anonymous 2010-06-17 23:59

>>49-50
I forgot to mention these are both Befunge-98. Befunge-93 doesn't know what a and b are.

Name: Anonymous 2010-06-18 0:12

>>52
For code that I wrote, posted, and then checked to see if it worked, I am happy. Does this make you slightly less annoyed:

++++++[>++++++++<-]>
>++++++++++>+++++++++[<<+.>.>-]
<<--------.-.>.

Name: Anonymous 2010-06-18 0:40

(loop for i from 1 to 10 do (print i))

Name: Anonymous 2010-06-18 0:47

for i in range(1,11): print i

Name: Anonymous 2010-06-18 1:01


class one210():
  def __init__(self):
    self.n = 0 #ALWAYS INIT UR VARS
  def count(self, by):
    self.n += by
  def show(self):
    print self.n

one2ten = one210()
i = 0
while i < 10:
  one2ten.count(1)
  one2ten.show()
  i += 1

Name: Anonymous 2010-06-18 1:24

say for 1..10

Name: Anonymous 2010-06-18 1:28

main = mapM_ (map show [1..10])

Name: Anonymous 2010-06-18 1:34

>>59
main = mapM_ print [1..10]

Name: Anonymous 2010-06-18 1:57

>>57
Not enterprise enough. I will give examples for both 0-based and 1-based.

def PrintFunction(string):
    print string

class Policies:
    IncrementPolicy = 1
    DecrementPolicy = 2
    ProductPolicy = 3
    DivisionPolicy = 4
    def __init__(self, policy):
        self._policy = policy

    def doOperation(self, numeric, policyChange = 1):
        p = self._policy
        if p == self.IncrementPolicy: return numeric + policyChange
        if p == self.DecrementPolicy: return numeric - policyChange
        if p == self.ProductPolicy: return numeric * policyChange
        if p == self.DivisionPolicy: return numeric / policyChange

    def startHigh(self):
        p = self._policy
        if p == self.IncrementPolicy: return False
        if p == self.DecrementPolicy: return True
        if p == self.ProductPolicy: return False
        if p == self.DivisionPolicy: return True

class Counter:
    def __init__(self, policy, printFunc = PrintFunction, min = 0, max = 10, step = 1, autoReset = True):
        self._min = min
        self._max = max
        self._step = step
        self._policy = Policies(policy)
        self._startHigh = self._policy.startHigh()
        self._printFunc = printFunc
        self._autoReset = autoReset

        if self._startHigh: self._cur = max
        else: self._cur = min

        printFunc("%d" % self._cur)

    def process(self):
        self._cur = self._policy.doOperation(self._cur, self._step)
        printFunc = self._printFunc

        printFunc("%d" % self._cur)

        if self._startHigh and self._cur <= self._min:
            printFunc("Finished iteration")
            if self._autoReset:
                self._cur = self._max
                printFunc("Restarting")
            else: return False

        elif not self._startHigh and self._cur >= self._max:
            printFunc("Finished iteration")
            if self._autoReset:
                self._cur = self._min
                printFunc("Restarting")
            else: return False

        return True

def TestSuite(oneBased = False):
    y = 0
    if oneBased: y = 1
    x = Counter(Policies.IncrementPolicy, PrintFunction, y, 10, 1, False)
    while x.process():
        continue

TestSuite()

Name: Anonymous 2010-06-18 2:32

[code]
#lang scheme
(define (count-from start end)
  (if (= start end)
      (and(newline)end)
      (and (newline)
           (display start)
           (count-from (inc start) end))))
     
(define (inc x)
   (+ x 1))
 
(count-from 1 10)
[code]

Name: Anonymous 2010-06-18 2:32


#lang scheme
(define (count-from start end)
  (if (= start end)
      (and(newline)end)
      (and (newline)
           (display start)
           (count-from (inc start) end))))
     
(define (inc x)
   (+ x 1))
 
(count-from 1 100)

Name: Anonymous 2010-06-18 16:13

>>31
This program is actually pretty enjoyable. You all should compile it and have a laugh.

Name: Anonymous 2010-06-18 16:18

>>64
It doesn't even compile on a ANSI-conforming compiler. It mixes C99 with C89.

Name: Anonymous 2010-06-18 16:22

using and instead of begin
W-D

Name: Anonymous 2010-06-18 16:25

10.times {|x| puts "#{x+1}\n"}

Name: Anonymous 2010-06-18 17:38

#!/usr/bin/perl
for (1..10) print "$_\n";

Name: Anonymous 2010-06-18 17:46

>>68
syntax error at line 2, near ") print"
Execution aborted due to compilation errors.

Name: Anonymous 2010-06-18 17:57

>>69
had shell programming on my mind. forgot the braces

#!/usr/bin/perl
for (1..10) { print "$_\n" };

Name: Anonymous 2010-06-18 17:59

>>68
Perl does not work that way.

print map "$_\n",1..10

Name: Anonymous 2010-06-18 18:06

Perl, so elegant and beautiful.

Name: Anonymous 2010-06-18 18:29

>>54
I didn't say I was annoyed, but seriously: do use code tags.

The other was just a tip.

Name: Anonymous 2010-06-18 18:37


#include <stdio.h>

void main(){
  int i = 0;
  while (i < 10)
    printf("%d\n", ++i);
}


@ >>26 lol

Name: Anonymous 2010-06-18 18:48

Α ← 0 Β ← 1 α ← 1 β ← 1 « α ≯ 10 α → Λ + → α »

Name: Anonymous 2010-06-18 18:56

>>75
Once again the syntax highlighter fucks up royally.

Name: Anonymous 2010-06-18 19:02

>>76
The syntax highlighter is doing it's job perfectly. It's one of the few parts of shiichan that actually works 100% all the time.

Name: Anonymous 2010-06-18 19:28

>>77
I don't think nothing but purple and green is considered acceptable highlighting in any language, even esoteric ones.

Name: Anonymous 2010-06-18 20:10

>>78
That's cool and all, but colorblindness disqualifies you from getting to make aesthetic calls of that sort.

Name: Anonymous 2010-06-18 21:51

>>79
I know it's hard to imagine as a girl, but most men are colorblind. You can't just disqualify them from putting a value on sensory perception like that.
But fine, brown ochre and dark cyan, if you prefer. It's still hideous.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List