# [Community Puzzle] abcdefghijklmnopqrstuvwxyz

Coding Games and Programming Challenges to Code Better

Created by @renzyGo,validated by @FredericLocquet,@Regulus136 and @field3.
If you have any issues, feel free to ping them.

This was very challenging, and I enjoyed and learned; very easy to understand the goal.
And I LOVE the title of the challenge. Hilarious. Thanks!

I noticed you don’t have a “Test5”… It goes from “Test 4” to “Test 6” which definitely seems odd, so just letting you know that if you want to change it.

3 Likes

Thank you.
I fixed the title in the test case.
I didn’t notice the mistakes in the title of the test case at all.

2 Likes

Nice puzzle!
I spend 5 minutes debugging my solution only to find that I spelled the alphabet wrong… Gotta go back to learn the classics I guess!

1 Like

I had all the test cases right but still got 80% because of the validators at test case 4,
why?
n = int(input())

p = []

q = []

for i in range(n):

``````p += [list(input())]
``````

for i in range(n):

``````q += [[]]

for _ in range(n):

q[-1] += ['-']
``````

for i in range(n):

``````o = ord('a')

for j in range(len(p[i])):

if ord(p[i][j]) == o:

a,b = i,p[i].index(p[i][j])

while True:

q[a][b] = chr(o)

o += 1

c = p[min(a+1,n-1)][b]

d = p[a][min(b+1,n-1)]

e = p[a][min(b-1,n-1)]

f = p[min(a-1,n-1)][b]

if ord('z') == o-1:break

if ord(c) == o : a+=1

elif ord(d) == o : b+=1

elif ord(e) == o : b-=1

elif ord(f) == o: a-=1

else:

q = []

for s in range(n):

q += [[]]

for _ in range(n):

q[-1] += ['-']

o = ord('a')

p[i][p[i].index(chr(o))] = '.'

if chr(o) not in p[i]:

break

b += 1

if ord('z') == o-1:

for i in q:

print(''.join(i))

quit()
``````

this is my solution and I don’t get why i didn’t get the 100%

1 Like

Please format your code properly using the </> button in the toolbar for others to examine your code.

1 Like

I understood the description and for me the validators worked.
I liked this puzzle!

Thank you! 1 Like

Thank you.

The validators don’t test for branching paths. Hope it saves some effort.

2 Likes

Tests provided in the IDE have been successfully passed, but when I submitted the solution Validator 3, Validator 4 and Validator 5 fail. Why ?

1 Like

Yeah, knowing this makes solving it a little easier, since there is no need to come back upstream if a branch ends prematurely. I’d also argue that this makes the labels of BFS and DFS not 100% correct. Maybe there could be (or is already) a harder version of this which accounts for branching.

Still a fun puzzle to solve.

3 Likes

Thank you.
I’m not sure if this will be helpful or not, but let me write a comment.
If you find the letter a, look up, down, left, and right to find b. Continue to search for the next character and examine up, down, left, and right. I think that this solution can solve the problem of this program (includes validation 3, 4, 5). Thanks.

1 Like

i don’t understand

First, you copy and paste your code. Then you highlight all of it. And then you click the </> button in the toolbar (see screenshot below). Your code should then be formatted and shown properly in this forum.

Hello, same for me and I don’t understand your answer. Is it possible to update the test cases please?

My code below if you want to have a look:

``````import sys

import math

# Auto-generated code below aims at helping you parse

# the standard input according to the problem statement.

def cleanTable():

table = []

for j in range(n):

emptyLine = ''

for i in range(len(m)):

emptyLine += '-'

table.append(emptyLine)

return table

def updateTable(table,i,j,letter):

line = list(table[i])

line[j] = letter

line = ''.join(line)

table[i] = line

return table

def updateIdx(i,j,n,m):

j+=1

if j==len(m)-1:

i+=1

j=0

return i,j

def getLetterAround(m,i,j):

upL,downL,leftL,rightL = ["\$","\$","\$","\$"]

if i==0: #first line

downL = m[i+1][j]

elif i==n-1: #last line

upL = m[i-1][j]

else: #middle line

downL = m[i+1][j]

upL = m[i-1][j]

#get left and right

if j==0: #leftest char

rightL = m[i][j+1]

elif j==len(m)-1: #rightest char

leftL = m[i][j-1]

else: #middle char

rightL = m[i][j+1]

leftL = m[i][j-1]

return upL,downL,leftL,rightL

n = int(input())

m = []

for i in range(n):

m.append(input())

#create the table full of line

table = cleanTable()

alphabet = 'abcdefghijklmnopqrstuvwxyz'

idxAlpha,i,j = [0,0,0] #init index

while idxAlpha<len(alphabet):

iprev = i

jprev = j

currentLetter = m[i][j]

upL,downL,leftL,rightL = ["*","*","*","*"]

if currentLetter == alphabet[idxAlpha]:

upL,downL,leftL,rightL=getLetterAround(m,i,j)

#compare with neighbours and update index and table

if currentLetter==alphabet[-1]:

table = updateTable(table,i,j,alphabet[-1])

break

if upL == alphabet[idxAlpha+1]:

i -= 1

elif downL == alphabet[idxAlpha+1]:

i += 1

elif leftL == alphabet[idxAlpha +1]:

j -= 1

elif rightL == alphabet[idxAlpha + 1]:

j+=1

if i!=iprev or j!=jprev:

table = updateTable(table,iprev,jprev,alphabet[idxAlpha])

idxAlpha += 1

else:

# if consecutive letters but not until "z", clean and start over

if idxAlpha !=0:

table = cleanTable()

idxAlpha = 0

[i,j] = updateIdx(i,j,n,m)

if i==n:

break

else:

[i,j] = updateIdx(i,j,n,m)

if i==n:

break

# Write an answer using print

# To debug: print("Debug messages...", file=sys.stderr, flush=True)

for tab in table:

print(tab)
``````

I’ve run your code on the validators. The error is (for all the last three validators):

Process has timed out. This may mean that your solution is not optimized enough to handle some cases.

The issue is that the while loop never breaks.

Really good puzzle, loved solving it.
I didn’t have much experience in recursive function and I learned a lot.

No spoil

However, I think I struggled for nothing while making a function that uses the list of all the indices of the 'a’s instead of doing 1 by 1 by browsing the array but i sill managed to do it like this

All tests passed. Validator3, Validator4, Validator5 not passed ! Have no idea why. Please check validators or put one of them to tests. Here is my code.

``````#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
int n;
string temp="bcdefghijklmnopqrstuvwxyza";
cin >> n; cin.ignore();
vector<string> field (n);
string m;
for (int i = 0; i < n; i++)
{
cin >> m; cin.ignore();
field[i]=m;
}
int it=0;
for (int y=0; y<n; ++y)
{
for (int x=0; x<m.size(); ++x)
{
if (field[y][x]=='a')
{
while (temp[it]!='a')
{
if (y-1>=0 and field[y-1][x]==temp[it]) {y--;}
else if (y+1<n and field[y+1][x]==temp[it]) {y++;}
else if (x-1>=0 and field[y][x-1]==temp[it]) {x--;}
else if (x+1<m.size() and field[y][x+1]==temp[it]) {x++;}
else
{
it=0;
break;
}
it++;
}
}
if (it){break;}
}
if (it){break;}
}

for (int y=0; y<n; ++y)
{
for (int x=0; x<m.size(); ++x)
{