Skip to main content
added 771 characters in body
Source Link
Jakube
  • 22k
  • 3
  • 28
  • 108

Pyth, 25 24 bytes

eu?]?.xGHsGtG+GhHmqd\:zY 

Got an idea by studying @isaacg's solution. But I'm using a stack.

Online Demonstration or [Test Suite][2]

Explanation

The first thing I do is to convert the input string into 0s and 1s. A "." gets converted into a 0, a ":" into a 1.

mqd\:z map each char d of input to (d == ":") 

Then I reduce this list of numbers:

eu?]?.xGHsGtG+GhHmqd\:zY u Y start with the empty stack G = [] for each H in (list of 0s and 1s), update G: G = ?.xGHsG product of G if H != 0 else sum of G ] wrapped in a list ? tG if G has more than 1 element else +GhH G + (H + 1) e take the top element of the stack 

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%3F.xGHsGtG%2BGhHmqd%5C%3AzYb&input=Test+cases%0A.+1%0A%3A+2%0A...+2%0A..%3A+1%0A.%3A.+3%0A.%3A%3A+2%0A%3A..+3%0A%3A.%3A+2%0A%3A%3A.+4%0A%3A%3A%3A+4%0A.....+3%0A....%3A+2%0A...%3A.+4%0A...%3A%3A+4%0A..%3A..+2%0A..%3A.%3A+1%0A..%3A%3A.+3%0A..%3A%3A%3A+2%0A.%3A...+4%0A.%3A..%3A+3%0A.%3A.%3A.+5%0A.%3A.%3A%3A+6%0A.%3A%3A..+3%0A.%3A%3A.%3A+2%0A.%3A%3A%3A.+4%0A.%3A%3A%3A%3A+4%0A%3A....+4%0A%3A...%3A+3%0A%3A..%3A.+5%0A%3A..%3A%3A+6%0A%3A.%3A..+3%0A%3A.%3A.%3A+2%0A%3A.%3A%3A.+4%0A%3A.%3A%3A%3A+4%0A%3A%3A...+5%0A%3A%3A..%3A+4%0A%3A%3A.%3A.+6%0A%3A%3A.%3A%3A+8&debug=0

Pyth, 25 24 bytes

eu?]?.xGHsGtG+GhHmqd\:zY 

Got an idea by studying @isaacg's solution. But I'm using a stack.

Online Demonstration or [Test Suite][2]

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%3F.xGHsGtG%2BGhHmqd%5C%3AzYb&input=Test+cases%0A.+1%0A%3A+2%0A...+2%0A..%3A+1%0A.%3A.+3%0A.%3A%3A+2%0A%3A..+3%0A%3A.%3A+2%0A%3A%3A.+4%0A%3A%3A%3A+4%0A.....+3%0A....%3A+2%0A...%3A.+4%0A...%3A%3A+4%0A..%3A..+2%0A..%3A.%3A+1%0A..%3A%3A.+3%0A..%3A%3A%3A+2%0A.%3A...+4%0A.%3A..%3A+3%0A.%3A.%3A.+5%0A.%3A.%3A%3A+6%0A.%3A%3A..+3%0A.%3A%3A.%3A+2%0A.%3A%3A%3A.+4%0A.%3A%3A%3A%3A+4%0A%3A....+4%0A%3A...%3A+3%0A%3A..%3A.+5%0A%3A..%3A%3A+6%0A%3A.%3A..+3%0A%3A.%3A.%3A+2%0A%3A.%3A%3A.+4%0A%3A.%3A%3A%3A+4%0A%3A%3A...+5%0A%3A%3A..%3A+4%0A%3A%3A.%3A.+6%0A%3A%3A.%3A%3A+8&debug=0

Pyth, 25 24 bytes

eu?]?.xGHsGtG+GhHmqd\:zY 

Got an idea by studying @isaacg's solution. But I'm using a stack.

Online Demonstration or [Test Suite][2]

Explanation

The first thing I do is to convert the input string into 0s and 1s. A "." gets converted into a 0, a ":" into a 1.

mqd\:z map each char d of input to (d == ":") 

Then I reduce this list of numbers:

eu?]?.xGHsGtG+GhHmqd\:zY u Y start with the empty stack G = [] for each H in (list of 0s and 1s), update G: G = ?.xGHsG product of G if H != 0 else sum of G ] wrapped in a list ? tG if G has more than 1 element else +GhH G + (H + 1) e take the top element of the stack 

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%3F.xGHsGtG%2BGhHmqd%5C%3AzYb&input=Test+cases%0A.+1%0A%3A+2%0A...+2%0A..%3A+1%0A.%3A.+3%0A.%3A%3A+2%0A%3A..+3%0A%3A.%3A+2%0A%3A%3A.+4%0A%3A%3A%3A+4%0A.....+3%0A....%3A+2%0A...%3A.+4%0A...%3A%3A+4%0A..%3A..+2%0A..%3A.%3A+1%0A..%3A%3A.+3%0A..%3A%3A%3A+2%0A.%3A...+4%0A.%3A..%3A+3%0A.%3A.%3A.+5%0A.%3A.%3A%3A+6%0A.%3A%3A..+3%0A.%3A%3A.%3A+2%0A.%3A%3A%3A.+4%0A.%3A%3A%3A%3A+4%0A%3A....+4%0A%3A...%3A+3%0A%3A..%3A.+5%0A%3A..%3A%3A+6%0A%3A.%3A..+3%0A%3A.%3A.%3A+2%0A%3A.%3A%3A.+4%0A%3A.%3A%3A%3A+4%0A%3A%3A...+5%0A%3A%3A..%3A+4%0A%3A%3A.%3A.+6%0A%3A%3A.%3A%3A+8&debug=0

edited body
Source Link
Jakube
  • 22k
  • 3
  • 28
  • 108

Pyth, 2525 24 bytes

eu?]@,]?.xGsGHtG+GHmhqd\xGHsGtG+GhHmqd\:zY 

Got an idea by studying @isaacg's solution. But I'm using a stack.

Online DemonstrationOnline Demonstration or [Test Suite][2]

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%40%2C%2Ceu%3F%5D%3F.xGsGHtG%2BGHmhqd%5C%3AzYb&input=Test%20cases%0AxGHsGtG%2BGhHmqd%5C%3AzYb&input=Test+cases%0A.%201%0A%3A%202%0A+1%0A%3A+2%0A...%202%0A+2%0A..%3A%201%0A%3A+1%0A.%3A.%203%0A+3%0A.%3A%3A%202%0A%3A%3A%3A+2%0A%3A..%203%0A%3A+3%0A%3A.%3A%202%0A%3A%3A%3A+2%0A%3A%3A.%204%0A%3A%3A%3A%204%0A+4%0A%3A%3A%3A+4%0A.....%203%0A+3%0A....%3A%202%0A%3A+2%0A...%3A.%204%0A+4%0A...%3A%3A%204%0A%3A%3A+4%0A..%3A..%202%0A+2%0A..%3A.%3A%201%0A%3A+1%0A..%3A%3A.%203%0A+3%0A..%3A%3A%3A%202%0A%3A%3A%3A+2%0A.%3A...%204%0A+4%0A.%3A..%3A%203%0A%3A+3%0A.%3A.%3A.%205%0A+5%0A.%3A.%3A%3A%206%0A%3A%3A+6%0A.%3A%3A..%203%0A+3%0A.%3A%3A.%3A%202%0A%3A+2%0A.%3A%3A%3A.%204%0A+4%0A.%3A%3A%3A%3A%204%0A%3A%3A%3A%3A%3A+4%0A%3A....%204%0A%3A+4%0A%3A...%3A%203%0A%3A%3A+3%0A%3A..%3A.%205%0A%3A+5%0A%3A..%3A%3A%206%0A%3A%3A%3A+6%0A%3A.%3A..%203%0A%3A+3%0A%3A.%3A.%3A%202%0A%3A%3A+2%0A%3A.%3A%3A.%204%0A%3A+4%0A%3A.%3A%3A%3A%204%0A%3A%3A%3A%3A%3A+4%0A%3A%3A...%205%0A%3A%3A+5%0A%3A%3A..%3A%204%0A%3A%3A%3A+4%0A%3A%3A.%3A.%206%0A%3A%3A+6%0A%3A%3A.%3A%3A%208&debug=0%3A%3A+8&debug=0

Pyth, 25 bytes

eu?]@,.xGsGHtG+GHmhqd\:zY 

Got an idea by studying @isaacg's solution. But I'm using a stack.

Online Demonstration or [Test Suite][2]

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%40%2C.xGsGHtG%2BGHmhqd%5C%3AzYb&input=Test%20cases%0A.%201%0A%3A%202%0A...%202%0A..%3A%201%0A.%3A.%203%0A.%3A%3A%202%0A%3A..%203%0A%3A.%3A%202%0A%3A%3A.%204%0A%3A%3A%3A%204%0A.....%203%0A....%3A%202%0A...%3A.%204%0A...%3A%3A%204%0A..%3A..%202%0A..%3A.%3A%201%0A..%3A%3A.%203%0A..%3A%3A%3A%202%0A.%3A...%204%0A.%3A..%3A%203%0A.%3A.%3A.%205%0A.%3A.%3A%3A%206%0A.%3A%3A..%203%0A.%3A%3A.%3A%202%0A.%3A%3A%3A.%204%0A.%3A%3A%3A%3A%204%0A%3A....%204%0A%3A...%3A%203%0A%3A..%3A.%205%0A%3A..%3A%3A%206%0A%3A.%3A..%203%0A%3A.%3A.%3A%202%0A%3A.%3A%3A.%204%0A%3A.%3A%3A%3A%204%0A%3A%3A...%205%0A%3A%3A..%3A%204%0A%3A%3A.%3A.%206%0A%3A%3A.%3A%3A%208&debug=0

Pyth, 25 24 bytes

eu?]?.xGHsGtG+GhHmqd\:zY 

Got an idea by studying @isaacg's solution. But I'm using a stack.

Online Demonstration or [Test Suite][2]

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%3F.xGHsGtG%2BGhHmqd%5C%3AzYb&input=Test+cases%0A.+1%0A%3A+2%0A...+2%0A..%3A+1%0A.%3A.+3%0A.%3A%3A+2%0A%3A..+3%0A%3A.%3A+2%0A%3A%3A.+4%0A%3A%3A%3A+4%0A.....+3%0A....%3A+2%0A...%3A.+4%0A...%3A%3A+4%0A..%3A..+2%0A..%3A.%3A+1%0A..%3A%3A.+3%0A..%3A%3A%3A+2%0A.%3A...+4%0A.%3A..%3A+3%0A.%3A.%3A.+5%0A.%3A.%3A%3A+6%0A.%3A%3A..+3%0A.%3A%3A.%3A+2%0A.%3A%3A%3A.+4%0A.%3A%3A%3A%3A+4%0A%3A....+4%0A%3A...%3A+3%0A%3A..%3A.+5%0A%3A..%3A%3A+6%0A%3A.%3A..+3%0A%3A.%3A.%3A+2%0A%3A.%3A%3A.+4%0A%3A.%3A%3A%3A+4%0A%3A%3A...+5%0A%3A%3A..%3A+4%0A%3A%3A.%3A.+6%0A%3A%3A.%3A%3A+8&debug=0

edited body
Source Link
Jakube
  • 22k
  • 3
  • 28
  • 108

Pyth, 25 bytes

eu?]@,.xGsGHtG+GHmhqd\:zY 

Base onGot an unspoken observation of @isaacgidea by studying @isaacg's solution. But I'm using a stack.

Online Demonstration or [Test Suite][2]

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%40%2C.xGsGHtG%2BGHmhqd%5C%3AzYb&input=Test%20cases%0A.%201%0A%3A%202%0A...%202%0A..%3A%201%0A.%3A.%203%0A.%3A%3A%202%0A%3A..%203%0A%3A.%3A%202%0A%3A%3A.%204%0A%3A%3A%3A%204%0A.....%203%0A....%3A%202%0A...%3A.%204%0A...%3A%3A%204%0A..%3A..%202%0A..%3A.%3A%201%0A..%3A%3A.%203%0A..%3A%3A%3A%202%0A.%3A...%204%0A.%3A..%3A%203%0A.%3A.%3A.%205%0A.%3A.%3A%3A%206%0A.%3A%3A..%203%0A.%3A%3A.%3A%202%0A.%3A%3A%3A.%204%0A.%3A%3A%3A%3A%204%0A%3A....%204%0A%3A...%3A%203%0A%3A..%3A.%205%0A%3A..%3A%3A%206%0A%3A.%3A..%203%0A%3A.%3A.%3A%202%0A%3A.%3A%3A.%204%0A%3A.%3A%3A%3A%204%0A%3A%3A...%205%0A%3A%3A..%3A%204%0A%3A%3A.%3A.%206%0A%3A%3A.%3A%3A%208&debug=0

Pyth, 25 bytes

eu?]@,.xGsGHtG+GHmhqd\:zY 

Base on an unspoken observation of @isaacg. But I'm using a stack.

Online Demonstration or [Test Suite][2]

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%40%2C.xGsGHtG%2BGHmhqd%5C%3AzYb&input=Test%20cases%0A.%201%0A%3A%202%0A...%202%0A..%3A%201%0A.%3A.%203%0A.%3A%3A%202%0A%3A..%203%0A%3A.%3A%202%0A%3A%3A.%204%0A%3A%3A%3A%204%0A.....%203%0A....%3A%202%0A...%3A.%204%0A...%3A%3A%204%0A..%3A..%202%0A..%3A.%3A%201%0A..%3A%3A.%203%0A..%3A%3A%3A%202%0A.%3A...%204%0A.%3A..%3A%203%0A.%3A.%3A.%205%0A.%3A.%3A%3A%206%0A.%3A%3A..%203%0A.%3A%3A.%3A%202%0A.%3A%3A%3A.%204%0A.%3A%3A%3A%3A%204%0A%3A....%204%0A%3A...%3A%203%0A%3A..%3A.%205%0A%3A..%3A%3A%206%0A%3A.%3A..%203%0A%3A.%3A.%3A%202%0A%3A.%3A%3A.%204%0A%3A.%3A%3A%3A%204%0A%3A%3A...%205%0A%3A%3A..%3A%204%0A%3A%3A.%3A.%206%0A%3A%3A.%3A%3A%208&debug=0

Pyth, 25 bytes

eu?]@,.xGsGHtG+GHmhqd\:zY 

Got an idea by studying @isaacg's solution. But I'm using a stack.

Online Demonstration or [Test Suite][2]

[2]: https://pyth.herokuapp.com/?code=FN.zAzbcN)%2Ceu%3F%5D%40%2C.xGsGHtG%2BGHmhqd%5C%3AzYb&input=Test%20cases%0A.%201%0A%3A%202%0A...%202%0A..%3A%201%0A.%3A.%203%0A.%3A%3A%202%0A%3A..%203%0A%3A.%3A%202%0A%3A%3A.%204%0A%3A%3A%3A%204%0A.....%203%0A....%3A%202%0A...%3A.%204%0A...%3A%3A%204%0A..%3A..%202%0A..%3A.%3A%201%0A..%3A%3A.%203%0A..%3A%3A%3A%202%0A.%3A...%204%0A.%3A..%3A%203%0A.%3A.%3A.%205%0A.%3A.%3A%3A%206%0A.%3A%3A..%203%0A.%3A%3A.%3A%202%0A.%3A%3A%3A.%204%0A.%3A%3A%3A%3A%204%0A%3A....%204%0A%3A...%3A%203%0A%3A..%3A.%205%0A%3A..%3A%3A%206%0A%3A.%3A..%203%0A%3A.%3A.%3A%202%0A%3A.%3A%3A.%204%0A%3A.%3A%3A%3A%204%0A%3A%3A...%205%0A%3A%3A..%3A%204%0A%3A%3A.%3A.%206%0A%3A%3A.%3A%3A%208&debug=0

Source Link
Jakube
  • 22k
  • 3
  • 28
  • 108
Loading