-2
(defn exp
  [n]
  (if (= n 0) 
      1
      (* 11 (exp (dec n)))))

(defn Pascals
  [n]
  (loop [x  n]
        (when (< 0 x)
              (println (exp (- x 1)))
              (recur (- x 1)))))

I need something like the Pascal's triangle from hackerrank

  • You might include a link to the bit you talk about in the last line. I assume it is this? https://www.hackerrank.com/challenges/pascals-triangle/problem – John Jones Nov 14 '17 at 00:38
  • What do you mean, invert? What does Pascal's triangle have to do with raising anything to the 11th power? This question is unclear and does not appear to relate to the included code. – amalloy Nov 14 '17 at 00:40

1 Answers1

1

Your function is printing as it's processed so the only way to flip the results is to flip the process.

What I mean is that if your function were to produce a collection of vectors like

(map triangle-row (range 1 4)) => ([1 2 1] [1 1] [1])

then you could just reverse the results of that

Here is your function with the process reversed:

(defn Pascals
  [n]
  (loop [x  0]
    (when (>= n x)
      (println (exp x))
      (recur (inc x)))))

instead of starting at n and going to 0, it starts as 0 and goes up.

But this doesn't fix the issue that it doesn't produce the proper output for pascal's triangle after the 8th row

Gary
  • 231
  • 1
  • 7