Skip to main content
4 of 5
added 133 characters in body
FUZxxl
  • 10.1k
  • 1
  • 38
  • 81

#J, 15 7 chars, 1 tie breaker, incomplete program

This is my J attempt. It is not a full program, because I have not yet figured out how to write one. Just put that line in a script to get the function p that can be used for adding an arbitrary amount of numbers. It is a monad and takes a list of numbers to add (such as p 1 2 3 4):

p=:#@#~

The idea is very simple. The function is written in tacit aka pointless style. Here is a pointed definition:

p=:3 :'##~y'

Read from right to left. In the tacit version, @ composes the parts of the function. (like a ∘ in mathematics [(f∘g)(x) = f(g(x)])

  • y is the parameter of p.
  • ~ makes a verb reflexive. For some verb m, m~ a is equal to a m a.
  • # (copy, a#b): Each element in a is replicated i times, where i is the element at the same index as the current element of a of b. Thus, #~ replicates an item n n times.
  • # (count, #b): Counts the number of elements in b.

Conclusion: J is awsome and less readable than Perl (that makes it even more awsome)

##Edits

  • 15 -> 7 using # instead of i.. Yeah! Less chars than golfscript.

##More of a program

This one queries for input, but it still isn't a full program: (13 chars, 3 breakers)

##~".1!:1<#a:
FUZxxl
  • 10.1k
  • 1
  • 38
  • 81