7
You will be given an ASCII text. This text may have zero, one or many appearances of a split a character (let's assume it will be the space character )
You will also be given an offset integer value (zero based) anywhere between zero and the length of the text.
You should calculate the relative offset inside the one split text, which contains the absolute offset, as well as the index of that very split text.
If the given offset is at the split character the last split should have the offset
It's hard to describe (comments welcome), so here are some examples
text: Lorem ipsum dolor sit amet
offset: 20
Lorem ipsum dolor sit amet
enter code here
--------------------^
000000000011111111112
012345678901234567890
Result: 2, 3
Explanation: If we split the text along the space characters, the split text, where the offset is in, is the fragment `sit` which is the 3rd split (count starts at zero) and the offset inside this fragment is 2
sit
--^
012
Some more examples
Text Offset Result
Lorem ipsum dolor sit amet 0 0, 0
^
Lorem ipsum dolor sit amet 1 1, 0
-^
Lorem ipsum dolor sit amet 2 2, 0
--^
Lorem ipsum dolor sit amet 3 3, 0
---^
Lorem ipsum dolor sit amet 4 4, 0
----^
Lorem ipsum dolor sit amet 5 5, 0
-----^
Lorem ipsum dolor sit amet 6 0, 1
------^
Lorem ipsum dolor sit amet 7 1, 1
-------^
Lorem ipsum dolor sit amet 8 2, 1
--------^
Lorem ipsum dolor sit amet 9 3, 1
---------^
Lorem ipsum dolor sit amet 10 4, 1
----------^
Lorem ipsum dolor sit amet 11 5, 1
-----------^
Lorem ipsum dolor sit amet 12 0, 2
------------^
Lorem ipsum dolor sit amet 13 1, 2
-------------^
Lorem ipsum dolor sit amet 14 2, 2
--------------^
Lorem ipsum dolor sit amet 15 3, 2
---------------^
Lorem ipsum dolor sit amet 16 4, 2
----------------^
Lorem ipsum dolor sit amet 17 5, 2
-----------------^
Lorem ipsum dolor sit amet 18 0, 3
------------------^
Lorem ipsum dolor sit amet 19 1, 3
-------------------^
Lorem ipsum dolor sit amet 20 2, 3
--------------------^
Lorem ipsum dolor sit amet 21 3, 3
---------------------^
Lorem ipsum dolor sit amet 22 0, 4
----------------------^
Lorem ipsum dolor sit amet 23 1, 4
-----------------------^
Lorem ipsum dolor sit amet 24 2, 4
------------------------^
Lorem ipsum dolor sit amet 25 3, 4
-------------------------^
Lorem ipsum dolor sit amet 26 4, 4
--------------------------^
If I am correctly interpreting your example, the second integer is the number of split characters in the first
offset
characters, the first is the character that is hit inside the chunk counted from its own origin? Do the two have anything in common? – Jonathan Frech – 2019-03-19T10:21:30.257@JonathanFrech I assume your thought on the second integer is correct. I don't understand your thought on the first character. And what do you mean by
Do the two have anything in common?
? – yunzen – 2019-03-19T10:24:49.457To me, the question appears to simply be two properties of a piece of text mangled together; I wanted to ask if there is any semantic connection between the two output integers. – Jonathan Frech – 2019-03-19T10:28:07.003
You want to now the reason why I ask this? It's inspired by this question on SE: https://stackoverflow.com/questions/55235774/text-area-getting-accurate-cursor-position-on-resize And I thought it would be an interesting question on CG
– yunzen – 2019-03-19T10:42:47.167Can we use 1 indexed instead of 0 indexed – Graham – 2019-03-19T10:45:11.923
I'd prefer 0 but I'm not bound to it – yunzen – 2019-03-19T10:45:43.140
5
"It's hard to describe (comments welcome)". This is why the Sandbox exists. When you want to create challenges, first lay them in the sandbox and let other people help you refine it.
– Olivier Grégoire – 2019-03-19T13:56:24.973