Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count to 10
#21
Can anyone point me to a pretty decent guide on C++ and Python?

Off-topic, I know.. But I've got nothing better to do than touch up on it.
Reply
#22
NVM didn' t read restrictions
Reply
#23
It specifically stated that you weren't allowed to type up the numbers 1-10 and just print that out.
Reply
#24
More fun. http://shakespearelang.sourceforge.net/

 SPL

Not entirely sure it works as I don't have the converter and can't compile it myself...
Reply
#25
Code:
public class countTen
{
    public static void main(String[] args) {
        System.out.println("1, 2, 3, 4, 5, 6, 7, 8, 9, 10");
    }
}

 ActionScript using Flixel Engine
Reply
#26
Eosian Wrote:You stated elegence was the target, short and succinct.
What did you expect?

I never said elegance and creativity were mutually exclusive.
Reply
#27
I suck then LOL.
Reply
#28
Arc (lisp dialect)
Code:
(for (i 1 10)
  (prn i))

I don't think it gets any easier. Maybe tail-recursion is more elegant?

Arc again
Code:
(def accum (acc)
  (prn acc)
  (if (< acc 10)
    (accum (1+ acc))))
    
(accum 1)

(Quick and dirty CLISP)
Code:
(loop for i from 1 to 10
  do (print i))

Orrr, since you'll usually have some sort of range-function defined
Code:
(defun range (a b)
  (loop for i from a to b
    collect i))
    
(format t "~{~D~%~}"
  (range 1 10))
Reply
#29
Those lisp code examples make me understand that XKDC comic.
[Image: lisp_cycles.png]
Reply
#30
Devil's Sunrise Wrote:Arc (lisp dialect)

Shidoshi Wrote:Those lisp code examples make me understand that XKDC comic.

http://ycombinator.com/arc/tut.txt

Oh my god.

I just read 1/3 of the way through and the lack of fluff already kind of amazes me. It's beautiful.
Reply
#31
shouri Wrote:R
Code:
seq(1:10)

You only need to write '1:10' and it'll output them. Probably works in MATLAB too, though I don't have a copy.

If you want it to actually print them,
Code:
cat(1:10)
Will give you the output you want. Or, to match with the other loops,
Code:
cat(1:10,sep="\n")
Will put each on a new line.


Getting into stupider methods of doing it in R...
Code:
y <- c(1:10,0)
x <- 1:11
c <- (lm(y ~ poly(x,10,raw=TRUE)))$coefficients
f <- function(x) {
  return(c[1] + c[2]*x + c[3]*x^2 + c[4]*x^3 + c[5]*x^4
         + c[6]*x^5 + c[7]*x^6 + c[8]*x^7 + c[9]*x^8
         + c[10]*x^9 + c[11]*x^10)
}
f(1:10)
Fit a degree 10 polynomial to the sequence, plus 0. Create a function that evaluates that polynomial. Then calculate the values of that function at the points 1 to 10.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)