Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Cumulative Counts

APL (Dyalog Unicode), 11 7 bytes (SBCS) Razetime and rak1507 came up with 7 byte equivalents of my original dfn (this one's rak1507's). See their solutions below. +/¨⊢=,\ Try it online! +/¨...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#6: Post edited by user avatar user‭ · 2021-04-18T16:12:43Z (about 3 years ago)
  • # [APL (Dyalog Unicode)], 11 bytes
  • <!-- language-all: lang-apl -->
  • {+/¨⍵=¨,\⍵}
  • [Try it online!][TIO-knme645v]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knme645v]: https://tio.run/##SyzI0U2pTMzJT///P@1R24Rqbf1DKx71brU9tEInBkjX/n/UNxUorpCmYAiERmBoCIbGCsZccEljBXMFUwUTBUugtDEQmymY/QcA "APL (Dyalog Unicode) – Try It Online"
  • ```
  • {+/¨⍵=¨,\⍵}
  • ,\⍵ ⍝ Prefixes of the list
  • ⍵=¨ ⍝ Compare every element to its corresponding prefix
  • +/ Count how many are equal in each prefix
  • ```
  • ### Also 11 bytes
  • <!-- language-all: lang-apl -->
  • +/⍤=¨∘(,\)⍨
  • [Try it online!][TIO-knmedn0d]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knmedn0d]: https://tio.run/##SyzI0U2pTMzJT//v@KhtQvWj3l1ApKABIh71bgUiEKVZCyTnKgTk51SmZebkKKTlFwEFlvxPA2rR1ne0PbTiUccMDZ0YzUe9K/4/6psKFFZIUzAEQiMwNARDYwVjLriksYK5gqmCiYIlUNoYiM0UzP4DAA "APL (Dyalog Unicode) – Try It Online"
  • # [APL (Dyalog Unicode)], <s>11</s> 7 bytes (SBCS)
  • Razetime and rak1507 came up with 7 byte equivalents of my original dfn (this one's rak1507's). See their solutions below.
  • <!-- language-all: lang-apl -->
  • +/¨⊢=,\
  • [Try it online!][TIO-knnd726n]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knnd726n]: https://tio.run/##SyzI0U2pTMzJT///P@1R2wRt/UMrHnUtstWJ@f@obypQQCFNwRAIjcDQEAyNFYy54JLGCuYKpgomCpZAaWMgNlMw@w8A "APL (Dyalog Unicode) – Try It Online"
  • ```
  • +/¨⊢=,\
  • ,\ ⍝ Prefixes of the list
  • = ⍝ Compare every prefix
  • to the corresponding element in the original list
  • +/ ⍝ Sum each to get a count of how many elements in each prefix match
  • ```
#5: Post undeleted by user avatar user‭ · 2021-04-17T23:55:29Z (about 3 years ago)
#4: Post edited by user avatar user‭ · 2021-04-17T23:55:06Z (about 3 years ago)
  • # [APL (Dyalog Unicode)], 11 bytes
  • <!-- language-all: lang-apl -->
  • {+/¨⍵=¨,\⍵}
  • [Try it online!][TIO-knme645v]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knme645v]: https://tio.run/##SyzI0U2pTMzJT///P@1R24Rqbf1DKx71brU9tEInBkjX/n/UNxUorpCmYAiERmBoCIbGCsZccEljBXMFUwUTBUugtDEQmymY/QcA "APL (Dyalog Unicode) – Try It Online"
  • ```
  • {+/¨⍵=¨,\⍵}
  • ,\⍵ ⍝ Prefixes of the list
  • ⍵=¨ ⍝ Compare every element to its corresponding prefix
  • +/ ⍝ Count how many are equal in each prefix
  • ```
  • # [APL (Dyalog Unicode)], 11 bytes
  • <!-- language-all: lang-apl -->
  • {+/¨⍵=¨,\⍵}
  • [Try it online!][TIO-knme645v]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knme645v]: https://tio.run/##SyzI0U2pTMzJT///P@1R24Rqbf1DKx71brU9tEInBkjX/n/UNxUorpCmYAiERmBoCIbGCsZccEljBXMFUwUTBUugtDEQmymY/QcA "APL (Dyalog Unicode) – Try It Online"
  • ```
  • {+/¨⍵=¨,\⍵}
  • ,\⍵ ⍝ Prefixes of the list
  • ⍵=¨ ⍝ Compare every element to its corresponding prefix
  • +/ ⍝ Count how many are equal in each prefix
  • ```
  • ### Also 11 bytes
  • <!-- language-all: lang-apl -->
  • +/⍤=¨∘(,\)⍨
  • [Try it online!][TIO-knmedn0d]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knmedn0d]: https://tio.run/##SyzI0U2pTMzJT//v@KhtQvWj3l1ApKABIh71bgUiEKVZCyTnKgTk51SmZebkKKTlFwEFlvxPA2rR1ne0PbTiUccMDZ0YzUe9K/4/6psKFFZIUzAEQiMwNARDYwVjLriksYK5gqmCiYIlUNoYiM0UzP4DAA "APL (Dyalog Unicode) – Try It Online"
#3: Post edited by user avatar user‭ · 2021-04-17T23:50:56Z (about 3 years ago)
  • # [APL (Dyalog Unicode)], 12 bytes
  • <!-- language-all: lang-apl -->
  • (1 1⍉+\)∘.=⍨
  • [Try it online!][TIO-knmbgria]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knmbgria]: https://tio.run/##SyzI0U2pTMzJT///P@1R2wQNQwXDR72d2jGajzpm6Nk@6l0BFFcACioYgaEhGBorGHOlKRjrmOuY6pjoWOoY6RgDsZmOGQA "APL (Dyalog Unicode) – Try It Online"
  • I'm nowhere near those brownie points, but that's fine, since I've been eating too many sweets these days.
  • Explanation:
  • ```
  • (1 1⍉+\)∘.=⍨
  • ∘.=⍨ ⍝ Compare every element with every other element
  • +\ Take the cumulative sum of each row of that boolean matrix
  • 1 1⍉Get the diagonal of that matrix
  • ```
  • # [APL (Dyalog Unicode)], 11 bytes
  • <!-- language-all: lang-apl -->
  • {+/¨⍵=¨,\⍵}
  • [Try it online!][TIO-knme645v]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-knme645v]: https://tio.run/##SyzI0U2pTMzJT///P@1R24Rqbf1DKx71brU9tEInBkjX/n/UNxUorpCmYAiERmBoCIbGCsZccEljBXMFUwUTBUugtDEQmymY/QcA "APL (Dyalog Unicode) – Try It Online"
  • ```
  • {+/¨⍵=¨,\⍵}
  • ,\⍵ ⍝ Prefixes of the list
  • ⍵=¨Compare every element to its corresponding prefix
  • +/ Count how many are equal in each prefix
  • ```
#2: Post deleted by user avatar user‭ · 2021-04-17T22:35:50Z (about 3 years ago)
#1: Initial revision by user avatar user‭ · 2021-04-17T22:35:30Z (about 3 years ago)
# [APL (Dyalog Unicode)], 12 bytes

<!-- language-all: lang-apl -->

    (1 1⍉+\)∘.=⍨

[Try it online!][TIO-knmbgria]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-knmbgria]: https://tio.run/##SyzI0U2pTMzJT///P@1R2wQNQwXDR72d2jGajzpm6Nk@6l0BFFcACioYgaEhGBorGHOlKRjrmOuY6pjoWOoY6RgDsZmOGQA "APL (Dyalog Unicode) – Try It Online"

I'm nowhere near those brownie points, but that's fine, since I've been eating too many sweets these days.

Explanation:
```
(1 1⍉+\)∘.=⍨
        ∘.=⍨ ⍝ Compare every element with every other element
     +\      ⍝ Take the cumulative sum of each row of that boolean matrix
 1 1⍉        ⍝ Get the diagonal of that matrix
```