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

Comments on Truthify an array

Post

Truthify an array

+7
−0

Jelly has an atom called untruth, which when given indices, creates an array with 1s at those places: [2,4] → [0,1,0,1].

You are required to perform the inverse of this. Given a 2D boolean array, find the indices of the true values in it.

Challenge

You will be given a single 2D boolean array $M$. You may take its dimensions as a separate argument if needed.

The output must consist of all the indices of the true values in $M$.

Output may be 0-indexed or 1-indexed.

It is guaranteed that the input will only consist of two different values.

Test Cases

All test cases are 0-indexed.

I: [[1,0,1,1,1,0]]
O: [[0,0],[0,2],[0,3],[0,4]]

I: [[1,0,1],[1,0,1],[0,1,0]]
O: [[0,0],[0,2],[1,0],[1,2],[2,1]]

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (5 comments)
General comments
Quintec‭ wrote over 3 years ago

Any number of dimensions is kind of annoying and severely limits some languages such as java - is there a reason for it?

Razetime‭ wrote over 3 years ago

@Quintec I allowed dimensions as a separate input if needed for that reason. Would it make more sense to have 2D arrays only?

Quintec‭ wrote over 3 years ago

Maybe, IMO any number of dimensions is just an extra I/O challenge that doesn't really have anything to do with the challenge idea (but that's just me perhaps)

Razetime‭ wrote over 3 years ago

Ok, I've changed it to take 2D arrays only.

Wezl‭ wrote about 3 years ago

Personally I prefer only requiring it to work for 1D arrays, which is simpler for most languages.