code golf

hi, it’s been quiet here for a while, so I’ll ask you for some code golf tips.
any thoughts how to shorten this k bit :

if[&/x in".“,l:(a;A)90>*x;1@/(1_,/|_[0,l?x;l]),'” \n"@#x]

link to requirements:

http://codegolf.stackexchange.com/questions/7036/print-custom-alphabet

ASCII arithmetic extends code too much.
some more tacit p may help, as well as inner map, instead of reduce ,’

definitely going to look at this one… does jsoftware mailing list(s)
know of it?

Some users certainly are aware, I’ve seen some neat J solutions there.

For this kind of competition, I wish :-) k/q could support :

  • implicit variables (perl alike) and
  • O(R|F)S (from awk), maybe {.z.rs, .z.fs}, or more of perl $ stuff
  • since (97=“a”) works…(“b”=“a”+1) would be outstanding
  • rotate as ASCII primitive in k
  • mod as ASCII code in k
  • here string/doc
  • native PCRE support

I understand that some of above are not q/k objectives, but anyway ;-)

Mentioned blown ASCII arithmetic (with small cheat- a,a…) ex.:
q)\d .Q
q.Q)i:“c.”
q.Q){y((7h$first i)+key 25)-x}.(96 65;(a,a;A,A))[;90>first i]
and it’s missing input check and RS join…
it’s not much better with rotate (and it’s missing in k).

Any ideas?
I’m loosing only one char with GolfScript now…
help! ;-)

On Fri, Aug 24, 2012 at 3:36 AM, Patryk Bukowinski <p.bukowinski@gmail.com> wrote:

hi, it’s been quiet here for a while, so I’ll ask you for some code golf tips.
any thoughts how to shorten this k bit :

if[&/x in".“,l:(a;A)90>*x;1@/(1_,/|_[0,l?x;l]),'” \n"@#x]

I can’t get it to work - a and A are undefined. ?is l the output?:

KDB+ 3.0 2012.08.07 Copyright (C) 1993-2012 Kx Systems

w32/ 4()core 3975MB jackandrews ltnbnxb087218h 192.168.1.3 PLAY 2012.11.05

q)\

? x:“d”

? if[&/x in".“,l:(a;A)90>*x;1@/(1_,/|_[0,l?x;l]),'” \n"@#x]

'A

?

link to requirements:

http://codegolf.stackexchange.com/questions/7036/print-custom-alphabet

ASCII arithmetic extends code too much.
some more tacit p may help, as well as inner map, instead of reduce ,'


Submitted via Google Groups

Hi Jack

On Fri, Aug 24, 2012 at 4:51 PM, Jack Andrews <effbiae@gmail.com> wrote:

On Fri, Aug 24, 2012 at 3:36 AM, Patryk Bukowinski <p.bukowinski@gmail.com> wrote:

hi, it’s been quiet here for a while, so I’ll ask you for some code golf tips.
any thoughts how to shorten this k bit :

if[&/x in".“,l:(a;A)90>*x;1@/(1_,/|_[0,l?x;l]),'” \n"@#x]

I can’t get it to work - a and A are undefined. ?is l the output?

Just run it from .Q namespace:
q)\d .Q
q.Q)A
“ABCDEFGHIJKLMNOPQRSTUVWXYZ”
q.Q)a
“abcdefghijklmnopqrstuvwxyz”

br,
B

if[&/x in".“,l:(a;A)90>*x;1@/(1_,/|_[0,l?x;l]),'” \n"@#x]

I can’t get it to work - a and A are undefined. ?is l the output?

Just run it from .Q namespace:
q)\d .Q
q.Q)A
“ABCDEFGHIJKLMNOPQRSTUVWXYZ”
q.Q)a
“abcdefghijklmnopqrstuvwxyz”

ah. ?maybe it’s a bit of a cheat to omit ? \d .Q ? from the solution??

but i think you can get away with leaving out the initial '' switch to k if your solution is in a .k file.

ta, jack.

but there’s nothing stopping a submitter defining a language designed as q is defined on k. ?

add any namespace changing and any other features…

true, but to be fair-play one should just use of the mill stuff.

there are plenty of guys down-voted for answers like:
“cstmAZ()” write compiler/interpreter on your own …
(beyond John Skeet on SO - but that’s 1st place karma…;-) )

I’ve already punished myself for global variable…
can’t beat this fancy GolfScript…

About 10 years ago i was a member of both communities and wrote manyprograms in both j and k to compare and contrast them. k always cameout on top in terms of succinctness. It is also much faster - it hasno guardrails to protect the user from himself. js guardrails addabout 50% to execution speed.Likely this comes from ks reliance on a single characters torepresent built in functions. j in contrast frequently uses two (ormore) where the second and subsequent characters are very low incontent (chosen from . and :). Arthur has looked at ks source code andconcluded that in most cases a ZIP actually INCREASES its size! k isvery near the limit imposed by information theory.Perhaps because of its small size and concision there is much lessproblem with user programs being outdated by a change in the languagerelease. This is a tremendous issue in the j community. That languagehas had frequent revolutions in format. They are for the better, butplay havoc with user code.i tried to make sense of one large program written in the previousversion of j, only to see it was unreadable because a machine hadforced it into a single file and the source form, which had severalfiles, was lost. So not only was in unexecutable it wasindecipherable.Likely the biggest program i published on the k list was a boggleprogram. i spent many hours of pleasurable activity with a TRS 100which implemented a Boggle board and timer making multiperson playeasy. i was eager to redo this in k, and wrote a version with an AIthat solved all puzzles for various board sizes and compiled variousdictionaries faster than one could hit the carriage return. Itextended the scoring procedure for long words by using a Fibonaccischeme.Eugene McDonnell (who wrote about Boggle in Vector magazine (number28, issue 18.1)) asked for this source code before writing his jversion and submitting it as an “at play” article. This version wasnot only much longer, but much slower than my k version. The primaryreason being a fundamental lack in the j language of a way ofaccessing ragged arrays. These are ubiquitous in language problemslike Boggle, but also in our modern XML based online world.One can simulate ragged arrays in j (of course it is a Turing machine)with boxing. There is nothing in j though that approaches the fluidityand speed of direct addressing in k, which inherited this from Scheme.http://www.jsoftware.com/jwiki/Doc/Articles/Play181 Eugene`s Bogglegreg~krsnadas.org

greg wrote:

> in most cases a ZIP actually INCREASES its size! k is

it is legend that zipping arthur’s code increases its size
? no bytes have the top bit set, so compression isn’t hard.

but i know what you mean. ?

we compress code - and we might be able to do it better than zip

JackA legend which Arthur contributed directly to by posting to it, as hecontributed to j by writing its ~Incunabulum.Not that Golfing is the best way to human efficacy, but it sure helpsto have everything visible.—~http://www.jsoftware.com/jwiki/Essays/Incunabulumhttp://jsoftware.com/pipermail/programming/2009-November/017017.htmlgreg~krsnadas.org--from: Jack Andrews effbiae@gmail.comto: personal-kdbplus@googlegroups.comdate: 26 August 2012 04:48subject: Re: [personal kdb+] code golfgreg wrote:> in most cases a ZIP actually INCREASES its size! k isit is legend that zipping arthur’s code increases its size no byteshave the top bit set, so compression isn’t hard.but i know what you mean.we compress code - and we might be able to do it better than zip

This may help reduce the code, and it has the advantage of not needing .q workspace:

? x:3 ?/“C”

? 10h$65+25#<x>!26

“DEFGHIJKLMNOPQRSTUVWXYZAB”

On Wed, Aug 29, 2012 at 2:06 PM, Jack Andrews <effbiae@gmail.com> wrote:

This may help reduce the code, and it has the advantage of not needing .q workspace:

? x:3 ?/“C”

? 10h$65+25#<x>!26

“DEFGHIJKLMNOPQRSTUVWXYZAB”

Will it handle “c.” case also? I did not test or run the code, so I’m just asking;-)
Regards,
Ba

<x> that’s neat :-)

I didn’t go this direction because of input param conversion, so decided to stick with string ops, namely: _

Tried simmilar aproach in second? email, it was aware of U/L case; even though was still missing input check…which takes most of the chars.

As I’ve mentioned, without char array arithmetic (“a”+65 - like c guys did, very clever stuff with masks etc..), it will be v. difficult to zip it more…