inputs
stringlengths 50
14k
| targets
stringlengths 4
655k
|
|---|---|
### Background
One way to order a nested (reddit-style) commenting system is by giving each comment a rank.
Generic comments on a thread start with rank 1 and increment, so the second comment on a thread would have rank 2. A reply to comment 1 will be ranked 1.1, and a reply to comment 1.1 will be ranked 1.1.1 . The second comment to reply to comment 1 would be ranked 1.2 .
Note that since 1.1.1 is a valid rank, the ranks given are of type string.
### Task:
Given a list of comment ranks (strings), order them as a comment thread would appear
### Assumptions:
* there will always be a rank 1 in the given input
* ranks are of type string
* rank numbers are incremented, and not skippped (1.1 could be followed by 1.2, not 1.3)
### Example order:
```
[
'1',
'1.1',
'1.2',
'1.2.1',
'2',
'3',
'3.1',
'3.1.1',
'3.2'
]
```
|
sort_ranks=lambda li,A=lambda li:max(li,key=lambda x:(int(x.split(".")[0]),x)).split(".")[0]:sum([sorted([k for k in li if k.split(".")[0]==str(i)])for i in range(1,int(A(li))+1)],[])
|
### Background
One way to order a nested (reddit-style) commenting system is by giving each comment a rank.
Generic comments on a thread start with rank 1 and increment, so the second comment on a thread would have rank 2. A reply to comment 1 will be ranked 1.1, and a reply to comment 1.1 will be ranked 1.1.1 . The second comment to reply to comment 1 would be ranked 1.2 .
Note that since 1.1.1 is a valid rank, the ranks given are of type string.
### Task:
Given a list of comment ranks (strings), order them as a comment thread would appear
### Assumptions:
* there will always be a rank 1 in the given input
* ranks are of type string
* rank numbers are incremented, and not skippped (1.1 could be followed by 1.2, not 1.3)
### Example order:
```
[
'1',
'1.1',
'1.2',
'1.2.1',
'2',
'3',
'3.1',
'3.1.1',
'3.2'
]
```
|
import re
def sort_ranks(ranks):
return sorted(ranks, key=lambda x: float(re.sub("(?<=\.\d)(\.)", "", x)))
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(tape):
ptr, stack, output = 0, [0], []
while ptr < len(tape):
command = tape[ptr]
if command == '^': stack.pop()
elif command == '!': stack.append(0)
elif command == '+': stack[-1] = (stack[-1] + 1) % 256
elif command == '-': stack[-1] = (stack[-1] - 1) % 256
elif command == '*': output.append(chr(stack[-1]))
elif command == '[' and stack[-1] == 0: ptr = tape.find(']', ptr)
elif command == ']' and stack[-1] != 0: ptr = tape.rfind('[', ptr)
ptr += 1
return ''.join(output)
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(s):
find, find_, d = [],[],{}
for i, j in enumerate(s):
if j == '[' : find.append(i)
if j == ']' : find_.append(i)
for i, j in zip(find, find_):
d[i] = j ; d[j] = i
memory,output,j = [0],[],0
while j < len(s):
i = s[j]
if i == "+" : memory[-1] = (memory[-1] + 1) % 256
if i == "-" : memory[-1] = (memory[-1] - 1) % 256
if i == '*' : output.append(chr(memory[-1]))
if i == "!" : memory.append(0)
if i == '[' :
if memory[-1] == 0 : j = d[j]
if i == "]" :
if memory[-1] != 0 : j = d[j]
if i == '^' : memory.pop(-1)
j += 1
return "".join(output)
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def pop(tape, pc, out, stack):
pc += 1
stack.pop()
return pc, out, stack
def zstack(tape, pc, out, stack):
pc += 1
stack.append(0)
return pc, out, stack
def inc(tape, pc, out, stack):
pc += 1
stack[-1] += 1
if stack[-1] > 255: stack[-1] = 0
return pc, out, stack
def dec(tape, pc, out, stack):
pc += 1
stack[-1] -= 1
if stack[-1] < 0: stack[-1] = 255
return pc, out, stack
def ascii(tape, pc, out, stack):
pc += 1
out += chr(stack[-1])
return pc, out, stack
def skip(tape, pc, out, stack):
pc += 1
if stack[-1] == 0:
c = tape[pc]
while c != "]":
pc += 1
c = tape[pc]
pc += 1
return pc, out, stack
def back(tape, pc, out, stack):
#return None
if stack[-1] != 0:
pc -= 1
c = tape[pc]
while c != "[":
pc -= 1
c = tape[pc]
pc += 1
else:
pc += 1
return pc, out, stack
dispatch = {
"^": pop,
"!": zstack,
"+": inc,
"-": dec,
"*": ascii,
"[": skip,
"]": back,
}
def interpreter(tape):
out = ""
stack = [0]
pc = 0
c = tape[pc]
while c:
if c in dispatch:
pc, out, stack = dispatch[c](tape, pc, out, stack)
else:
pc += 1
c = tape[pc: pc + 1]
return out
# Happy Coding! :)
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(tape):
out = []
stack = [0]
ip = 0
while ip < len(tape):
cmd = tape[ip]
if cmd == '^': stack.pop()
elif cmd == '!': stack.append(0)
elif cmd == '+': stack[-1] = (stack[-1] + 1) % 256
elif cmd == '-': stack[-1] = (stack[-1] - 1) % 256
elif cmd == '*': out.append(chr(stack[-1]))
elif cmd == '[':
if stack[-1] == 0:
while tape[ip] != ']': ip += 1
elif cmd == ']':
if stack[-1] != 0:
while tape[ip] != '[': ip -= 1
ip += 1
return ''.join(out)
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(tape):
ptr, stack, output = 0, [0], ''
n = len(tape)
while ptr < n:
cmd = tape[ptr]
if cmd == '^': stack.pop()
elif cmd == '!': stack.append(0)
elif cmd == '+': stack[-1] = (stack[-1] + 1) % 256
elif cmd == '-': stack[-1] = (stack[-1] + 255) % 256
elif cmd == '*': output += chr(stack[-1])
elif cmd == '[' and stack[-1] == 0:
while tape[ptr] != ']': ptr += 1
elif cmd == ']' and stack[-1] != 0:
while tape[ptr] != '[': ptr -= 1
ptr += 1
return output
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(tape):
stack, output = [0], ''
i, n = 0, len(tape)
while i < n:
cmd = tape[i]
if cmd == '^':
stack.pop()
elif cmd == '!':
stack.append(0)
elif cmd == '+':
stack[0] = 0 if stack[0] == 255 else stack[0] + 1
elif cmd == '-':
stack[0] = 255 if stack[0] == 0 else stack[0] - 1
elif cmd == '*':
output += chr(stack.pop(0))
elif cmd == '[' and stack[0] == 0:
while tape[i] != ']':
i += 1
elif cmd == ']' and stack[0] != 0:
while tape[i] != '[':
i -= 1
i += 1
return output.replace('\n', '\x02')
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def cleanTape(tape):
a = [x for x in tape if x in '^!+-*[]']
return ''.join(a)
def interpreter(tape):
tape = cleanTape(tape)
stack = [0]
index = 0
output = ''
while index < len(tape):
if tape[index] == '^':
stack.pop()
if tape[index] == '!':
stack.append(0)
if tape[index] == '+':
stack[-1] += 1
if tape[index] == '-':
stack[-1] -= 1
stack[-1] %= 256
if tape[index] == '*':
output += chr(stack[-1])
if tape[index] == '[':
if stack[-1] == 0:
i = index + 1
while True:
if tape[i] == ']':
index = i + 1
break
i += 1
continue
if tape[index] == ']':
if stack[-1] != 0:
i = index - 1
while True:
if tape[i] == '[':
index = i - 1
break
i -= 1
continue
index += 1
return output
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(tape):
stack = [0]
ip = 0
output = ''
while ip < len(tape):
op = tape[ip]
if op == '^':
stack.pop()
elif op == '!':
stack.append(0)
elif op == '+':
stack[-1] = (stack[-1] + 1) % 256
elif op == '-':
stack[-1] = (stack[-1] + 255) % 256
elif op == '*':
output += chr(stack[-1])
elif op == '[' and stack[-1] == 0:
ip = tape.find(']', ip + 1)
elif op == ']' and stack[-1] != 0:
ip = tape.rfind('[', 0, ip)
ip += 1
return output
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(tape):
a,stack,out=0, [0], []
while a<len(tape):
command=tape[a]
if command == '^': stack.pop()
elif command == '!': stack.append(0)
elif command == '+': stack[-1]=(stack[-1]+1) % 256
elif command == '-': stack[-1]=(stack[-1]-1) % 256
elif command == '*': out.append(chr(stack[-1]))
elif command == '[' and stack[-1]==0: a=tape.find(']', a)
elif command == ']' and stack[-1]!=0: a=tape.rfind('[', a)
a += 1
return ''.join(out)
|
# Task
Make a custom esolang interpreter for the language Stick. Stick is a simple, stack-based esoteric programming language with only 7 commands.
# Commands
* `^`: Pop the stack.
* `!`: Add new element to stack with the value of 0.
* `+`: Increment element. 255+1=0.
* `-`: Decrement element. 0-1=255.
* `*`: Add ascii value of **top** element to the output stream.
* `[`: Skip past **next** `]` if element value is 0.
* `]`: Jump back to the command after **previous** `[` if element value is nonzero.
# Syntax and other info
* You don't need to add support for nested brackets.
* Non-command characters should be ignored.
* Code will always have all brackets closed.
* Note the highlighted **next** and **previous** in the commands reference.
* Program begins with the top element having the value of 0 and being the only element in the stack.
* Program ends when command executor reaches the end.
# Examples
## Hello, World!
```python
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*!+++++++++++++++++++++++++++++++++*!'
```
# Notes
* If this kata is a duplicate, this is not an issue.
* If this kata uses incorrect styling, it is also not an issue.
* Feel free to comment in the discource area.
* Swift versions must throw an error (conforming to the Error Protocol) when abnormal conditions occur.
* Javascript versions should throw when abnormal conditions occur.
|
def interpreter(tape):
j, k = {}, []
for i in range(len(tape)):
if tape[i] == "[": k.append(i)
elif tape[i] == "]":
j[i] = k[-1]
j[k.pop()] = i
m, r, i, l = [0], "", 0, len(tape)
while i < l:
if tape[i] == "^": m.pop(0)
elif tape[i] == "!": m.append(0)
elif tape[i] == "+": m[-1] += 1
elif tape[i] == "-": m[-1] -= 1
elif tape[i] == "*": r += chr(m.pop(0) % 256)
elif (tape[i] == "[" and not m[-1] % 256) or (tape[i] == "]" and m[-1] % 256): i = j[i]
i += 1
return r
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(c * 2 for c in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
res = ''
for i in s:
res += i*2
return res
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(2 * c for c in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(str):
return "".join(ch+ch for ch in str)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(str):
return "".join(c*2 for c in str)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(char * 2 for char in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
y = list(s) # Breaks the string into individual letters
length = len(y) # Length of string
ffs = list(range(0,length)) # Creates an array beginning with 0, going up in ones, the length of the original string
blank="" # Blank string to build from
for i in ffs: # For (i)tems in ffs, number 0 thru x (length)
blank = blank + y[i] + y[i] # Essentially blank + list(0) + list(0), then blank + list(1) + list(1)
return blank
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
double_char = lambda s: ''.join(a*2 for a in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
double_char=lambda s:''.join(c+c for c in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
result = ""
for i in s:
result += i + i
return result
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join([x*2 for x in s])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(a*2 for a in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
OUTPUT = '{0}{0}'.format
def double_char(s):
return ''.join(OUTPUT(a) for a in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
result = ''
for char in s:
result += char * 2
return result
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
slowo = "" # defining new empty string for doubled word
for char in s: # loop going by every char in word s
char = 2 * char # for every char doubling it
slowo += char # adding doubled char to new string
return slowo
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
answer = []
for i in s:
answer.append(i)
answer.append(i)
return "".join(answer)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s: str) -> str:
""" Get a string in which each character is repeated once. """
return "".join(list(map(lambda _: _ * 2, "|".join(s).split("|"))))
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new=str()
for i in s:
new+=i+i
pass
return new
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(some_text):
return ''.join([2 * letter for letter in some_text])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join([2*i for i in s])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new_s = ""
for c in s:
new_s = "%s%c%c" % (new_s, c, c);
return new_s
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
s=list(s)
lists=[]
for i in range(len(s)):
lists.append(s[i]*2)
string=''
for i in range(len(lists)):
string=string+lists[i]
return string
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def addition(char):
return 2*char
def double_char(s):
result = list(map(addition, s))
return ''.join(result)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(map(lambda x:''.join(x), zip(s,s)))
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return(''.join([s[i]*2 for i in range(len(s))]))
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return reduce(lambda x,y: x+y, map(lambda x : 2*x, s))
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
double_char = lambda s: ''.join([i*2 for i in s])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new_list = []
for x in s:
new_list.append(x)
new_list.append(x)
return ''.join(new_list)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new = ""
for char in s:
new += char * 2
return new
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join([character+character for character in s])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
z = ""
for i in range(len(s)):
z += (s[i])
z += (s[i])
return z
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
total = ""
for i in s:
total += i
total += i
return total
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
rtrn = ''
for x in s:
rtrn += x*2
return rtrn
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
res = ''
for t in range(len(s)):
res += 2*s[t]
return res
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
res = ""
for l in s:
res += l+l
return res
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new_string = ""
for char in s:
char = char*2
new_string += char
return new_string
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
result = ''
for sym in s:
result += 2 * sym
return result
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
storage=""
for i in s:
storage+=i*2
return storage
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(string):
fin = ""
for char in string:
fin += char * 2
return fin
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
output = ""
for character in s:
output += 2 * character
return output
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
a = [i*2 for i in s]
return "".join(i for i in a)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
array = list(s)
count = len(array)-1
while count >= 0:
array.insert(count, array[count])
count += -1
return "".join(array)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
lst = list(s)
res = ''
for el in lst:
res += el * 2
return res
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
n = len(s)
result = ""
for i in range(n):
result += s[i] * 2
return result
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
r = ''
for x in s:
r += 2 * x
return r
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new_string = []
for i in list(s):
new_string.append(i+i)
return "".join(new_string)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
tustik=[i*2 for i in s]
return ''.join(tustik)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
sss = ''
for i in s:
sss += i + i
return sss
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
Liste = []
for i in s:
Liste.append(i*2)
return ''.join(Liste)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return_string = ""
for i in s:
return_string += i * 2
return return_string
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return_string = ""
for i in s:
return_string += i
return_string += i
return return_string
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
s = [i+i for i in s]
return ''.join(s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
my_list = ""
for i in range(len(list(s))):
my_list += str(list(s)[i]*2)
return my_list
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
hold = ""
for x in range(len(s)):
hold += (s[x] * 2)
return hold
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
str=''
for i in s:
str+=2*i
return str
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
dbl = ''
for i in range(len(s)):
dbl=dbl+s[i]+s[i]
return dbl
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
l = list(s)
res = []
for letter in l:
res.append(letter)
res.append(letter)
return "".join(res)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
chars = []
for char in s:
chars.append(char)
for i in range(len(chars)):
chars[i] = chars[i] * 2
return ''.join(chars)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join([next_str + next_str for next_str in s])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
ans = []
for i in s:
a = i * 2
ans.append(a)
return "".join(ans)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
str=""
for i in s:
i*=2
str+=i
return str
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
s2=""
for i in range(len(s)):
s2+=2*s[i]
return s2
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(['{}'.format(i[0]+i[1]) for i in zip(s,s)])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join([2*letter for letter in s])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join([''.join([r,r]) for r in s])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
lst=[]
for x in s:
lst.append(x)
lst.append(x)
lst = "".join(lst)
return lst
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
ans = ''
for i in s:
ans = ans + i * 2
return ans
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
derp = ""
for letters in s:
derp+=letters + letters
return derp
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return "".join([s[x]*2 for x in range(len(s))])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
word = ""
for char in s:
char = char * 2
word += char
return word
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
res = ''
for i in s:
res += f"{i}{i}"
return res
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
l = list(s)
r = []
for i in range(len(l)):
r.append(l[i]+l[i])
return ''.join(r)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
t = ''
for x in s:
t += x + x
return t
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
double = ""
for i in range(len(s)):
double += "{}".format(s[i]*2)
return double
double_char("String")
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
x = []
for i in range(len(s)):
x.append(2*s[i])
return ''.join(x)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
t = ""
for x in s:
t += x*2
return t
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
double_s = ''
for i, x in enumerate(s):
double_s += (x * 2)
return double_s
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
k = list(s)
arr = []
for i in range(len(s)):
arr.append(s[i])
arr.append(s[i])
return ''.join(arr)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
s = [lett*2 for lett in s]
y = ''
x = 0
while x < len(s):
y += s[x]
x +=1
return y
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
s = list(s)
returnArr = []
for i in range(len(s)):
returnArr.append(s[i])
returnArr.append(s[i])
return "".join(returnArr)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
#start with an empty string
x = ""
##loop across string s, and add each letter twice to empty string x
for i in range(len(s)):
x = x+s[i]+s[i]
return x
pass
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
lisp = ""
for char in s:
lisp = lisp + char + char
return lisp
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
ans = []
for i in s:
ans.append(i*2)
return "".join(ans)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
duplicados = ''
for char in s:
duplicados=duplicados+char+char
return duplicados
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
final_str = ""
for i in s:
final_str += i * 2
return final_str
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(list(char*2 for char in s))
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
returnString = ""
i = 0
while i < len(s):
returnString = returnString + s[i] + s[i]
i+= 1
return returnString
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return "".join([2*word for word in list(s)])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.