16
1
We all know that a lot of exercises only affect one half of your body, so you have to do them twice, once for each side. Such exercises have two counterparts, one for the left side and one for the right. However, there's no need to execute the two counterparts consecutively, as long as the exercises for both sides are in the same order. You may as well switch between sides in your exercise program, but it wouldn't make sense to start some exercises with one side and some with the other.
Challenge
An exercise part is a list of non-zero integers, where its second half consists of the integers of the first half negated and in the same order, and the signs of the integers on each half are equal. The sign of the first half of an exercise part is its leading side.
An exercise set is zero or more exercise parts with the same leading side concatenated together.
Given a list of non-zero integers as input, determine if it is an exercise set. The integers aren't necessarily unique. The list's length isn't necessarily even.
Your solution may not use any of the standard loopholes. You may use any two different consistent values for output. This is code-golf, so the shortest solution wins.
Examples
[-5, -1, -7, -6, -5, 5, 1, 7, 6, 5]
is an example of an exercise part. The first half is [-5, -1, -7, -6, -5]
, and the last half is [5, 1, 7, 6, 5]
, which is each integer in the first half negated. Additionally, the first half's integers are all of the same sign. This exercise part's leading side is -1
.
[3, 6, 5, -3, -6, -5, 1, 6, 4, 3, -1, -6, -4, -3]
is an example of an exercise set. Its individual exercise parts are [3, 6, 5, -3, -6, -5]
and [1, 6, 4, 3, -1, -6, -4, -3]
, and they both have leading side 1
.
[4, -4, -5, 5]
, despite only consisting of valid exercise parts, isn't an exercise set, since the first part, [4, -4]
, has leading side 1
, while the second part, [-5, 5]
, has leading side -1
.
Test cases
Valid test cases:
[]
[1, -1]
[1, -1, 1, -1]
[-6, 6, -5, -4, -3, 5, 4, 3]
[-1, -5, -8, 1, 5, 8, -7, -6, -5, -3, 7, 6, 5, 3]
[-1, -5, -8, 1, 5, 8, -1, 1]
Invalid test cases:
[1]
[1, -2]
[1, 2, -3, -1, -2, 3]
[1, 2, 3, -3, -1, -2]
[-1, -5, -8, 1, 5, 8, 7, 6, 5, 3, -7, -6, -5, -3]
[1, 2, 3, 5, 1, 2, 3, 5]
[1, 2, -5, 4, -6, 5, 5, -6]
[1, 2, -1, 3, -2, -3]
[1, -2, 1]
[-1, -1, 1]
[1, -1, 1]
3The empty case is an annoyance. And to interpret the words of the challenge I'm not sure if there is a valid way to assign "not exercising at all" to either one side or the other of "is it an exercise set?" But to be honest I'm just whining. – ngm – 2018-05-24T13:55:41.810
@ngm Was just about to comment this.. Empty list is an annoying edge case.. Personally I would state the input contains at least one item. Apart from that nice challenge, though! – Kevin Cruijssen – 2018-05-24T13:57:07.323
1@ngm It's truthy by terms of vacuous truth. Consider it to be proper relaxation. ;) – Erik the Outgolfer – 2018-05-24T14:03:36.870
2It's nice to know I can golf and exercise at the same time. – ngm – 2018-05-24T14:06:17.793
@ngm "It's nice to know I can golf and exercise at the same time." We got more of those kind of challenges. ;)
– Kevin Cruijssen – 2018-05-24T14:11:48.373This is hard AF in 05AB1E. – Magic Octopus Urn – 2018-05-24T21:39:45.307