#J, 15 7 chars, 1 tie breaker, incomplete program
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 ofp
.~
makes a verb reflexive. For some verbm
,m~ a
is equal toa m a
.#
(copy,a#b
): Each element ina
is replicatedi
times, wherei
is the element at the same index as the current element ofa
ofb
. Thus,#~
replicates an itemn
n
times.#
(count,#b
): Counts the number of elements inb
.
Conclusion: J is awsome and less readable than Perl (that makes it even more awsome)
##Edits
Edits
- 15 -> 7 using
#
instead ofi.
. Yeah! Less chars than golfscript.
##More of a program
More of a program
This one queries for input, but it still isn't a full program: (13 chars, 3 breakers)
##~".1!:1<#a: