Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- KX Community
- :
- Discussion Forums
- :
- kdb+ and q
- :
- Re: How this line works

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

How this line works

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2021.01.23 12:58 AM

Can someone explain me how the following line works line works:

Here the

Output **p** is NM * NM dimensional string list (i.e NM strings of length NM)

As an example, consider

*rs: 2 2# enlist 2 2# "a" *

then by doing**p: raze(,'/)' [rs]**

then by doing

we will get

aaaa

aaaa

aaaa

aaaa

aaaa

Can someone dissect the line and help me understand

TIA.

- Rohith

- Rohith

P.S

The code snippet from this excellent repo https://github.com/adotsch/aoc/blob/master/2020/day20.q which had concise and efficient Advent of code 2020 solutions. I found it when I was looking around to compare my solutions. I ve been trying to learn from his solutions but got stuck at that part.

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2021.01.23 02:37 AM

It will be easier to see it this way

q)rs:2 2 2 2#16#.Q.a

q)rs

"ab" "cd" "ef" "gh"

"ij" "kl" "mn" “op"

Now lets dissect (,’/)' one by one

Rightmost each(‘) is just iterating an top level lists in rs, so we can ignore that for the time being and directly look at rs[0]

q)(,'/)rs 0

"abef"

“cdgh"

this is basically a combination of dyadic over with each-both join (,')

kind of same as for a two element rs[0] — joining side ways

q)rs[0;0] ,' rs[0;1]

"abef"

"cdgh"

q)raze each flip rs 0

"abef"

“cdgh"

Now you do the same on all top level lists of rs using each (‘)

q)(,'/)'[rs]

"abef" "cdgh"

"ijmn" “klop"

then reduce the top dimension with raze

q)raze(,'/)'[rs]

"abef"

"cdgh"

"ijmn"

“klop"

You can condense it further by removing unnecessary brackets

q)raze(,'/')rs

"abef"

"cdgh"

"ijmn"

“klop"

-Ajay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2021.01.25 03:33 AM

Thank you, Ajay. The explanation is easy to follow!

Main Office Contacts

**EMEA**

Tel: +44 (0)28 3025 2242

**AMERICAS**

Tel: +1 (212) 447 6700

**APAC**

Tel: +61 (0)2 9236 5700

Useful Information

Resources

KX. All Rights Reserved.

KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.