Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 866715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:51:17+00:00 2026-05-15T09:51:17+00:00

I’ve been working on a J function for a while, that’s supposed to scan

  • 0

I’ve been working on a J function for a while, that’s supposed to scan a list and put consecutive copies of an element into separate, concatenated boxes. My efforts have taken me as far as the function

(<;. 2) ((2&(~:/\)),1:)

which tests successive list entries for inequality, returns a list of boolean values, and cuts the list into boxes that end each time the number 1 appears. Here’s an example application:

   (<;. 2) ((2&(~:/\)),1:) 1 2 3 3 3 4 1 1 1
+-+-+-----+-+-----+
|1|1|0 0 1|1|0 0 1|
+-+-+-----+-+-----+

The task would be finished if I could then replace all those booleans with their corresponding values in the input argument. I’ve been looking for some kind of mystery function that would let me do something like

   final =: mysteryfunction @ (<;. 2) ((2&(~:/\)),1:)

   final 1 2 3 3 3 4 1 1 1    
+-+-+-----+-+-----+
|1|2|3 3 3|4|1 1 1|
+-+-+-----+-+-----+

In an ideal situation, there would be some way to abstractly represent the nesting pattern generated by (<;. 2) ((2&(~:/\)),1:) and apply it to the original input list. (i.e. “This boxed array over here has the first element boxed at depth one, the second element boxed at depth one, the third, fourth, and fifth elements boxed together at depth one,…, so take that unboxed list over there and box it up the same way.”) I tried fooling around with ;. , S: , L:, L. and &. to produce that behavior, but I haven’t had much luck. Is there some kind of operator or principle I’m missing that could make this happen? It wouldn’t surprise me if I were overthinking the whole issue, but I’m running out of ideas.

EDIT:

At the moment, the only working solution I have is this one:

isduplicate =: ((2&(~:/\)),1:)

testfun =: 3 : 0
numduplicates =. #S:0 ((<;.2) isduplicate y)
distinctboxes =. <"0 (isduplicate#]) y
numduplicates # each distinctboxes
)

It’s a two-step process of generating the run-length encoding of the list and then undoing the encoding without getting rid of the boxes. Since I’m originally doing this with the aim of solving the 99 problems in tandem using J and Haskell, it feels like begging the question if I solve problem 9 by first solving problem 12.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:51:18+00:00Added an answer on May 15, 2026 at 9:51 am

    You’re almost there. Add a ~ and place the parentheses differently, and that’s it:

       (<;.2~ (2&(~:/\) , 1:)) 1 2 3 3 3 4 1 1 1
    ┌─┬─┬─────┬─┬─────┐
    │1│2│3 3 3│4│1 1 1│
    └─┴─┴─────┴─┴─────┘
    

    A quick explanation/illustration:

       s =: 1 2 3 3 3 4 1 1 1
    
       f =: 2&(~:/\) , 1:
       f s
    1 1 0 0 1 1 0 0 1
    
       g =: <;.2
    
       (f s) g s
    ┌─┬─┬─────┬─┬─────┐
    │1│2│3 3 3│4│1 1 1│
    └─┴─┴─────┴─┴─────┘
    

    Now that final (f s) g s, sometimes referred to as a “left hook”, can be written (g~ f) s (the adverb ~ is called “passive” in J, the Haskell counterpart would be flip). Alternatively you could also tacitly write this as the fork (f g ]) s.

    Chapter 9 of “Learning J” discusses this topic extensively, if you want to find out more.

    Update: I previously used a grouping-based (</.~ (+/\&(1,(2&(~:/\))))), but your original cut-based approach is more elegant (and shorter) than this. As this is really about the left hook, I updated to use your approach directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.