write a program to print this pattern #coding #programmer #problemsolving #solving #pattern

preview_player
Показать описание
write a program to print this pattern #coding #programmer #problemsolving #solving #pattern
pattern program,pattern program in python,draw pattern program,pattern,pattern in python,how to solve pattern questions in coding,pattern printing,problem solving in python,pattern questions in coding,pattern programs,write a c program to print alphabet in star pattern,write a c program to print ''v'' alphabet in star pattern,pattern printing programs,c program to print alphabet a star pattern,pattern program in c,number pattern program in java
Рекомендации по теме
Комментарии
Автор

print("2")
print("8 7")
print("13 12 10")
print("17 16 14 11")
print("20 19 17 14 10")

JohanLibert-cb
Автор

start = 2
rng = 1
for i in range(6, 1, -1):
num = start - 0
for j in range(1, rng+1):
print(num, end= " ")
num -= j
print()
start += i
rng += 1

hasibahmad
Автор

See carefully, each row decreases in terms of 1, 2, 3, 4 and so on, it is increasing in 4, 3, 2, 1 column wise of the first element, easy, :)

arjunraj
Автор

This is a pure mathematics question combined with basic programming

After some analysis i came down to a general formula (It took some time more than i anticipated)

T(i) = 2 + (i-1)*(14-i)/2

rows = 5
for i in range(1, rows+1):
start = 2 + (i-1)*(14-i)//2
for j in range(1, i+1):
print(start, end=‘’)
if j<i:
print(‘ ‘, end=‘’)
start -= j
print()

d.y
Автор

num_rows = 5
start = 2

for i in range(num_rows):
current = start
for j in range(i + 1):
print(current, end=" ")
current -= (i + 1 - j)
print()
start += (6 - i)

jrsrihari.b
Автор

def print_pattern():
start = 2
rows = 5

for i in range(rows):
current = start
# Calculate the starting number for each row
if i == 0:
current = 2
elif i == 1:
current = 8
elif i == 2:
current = 13
elif i == 3:
current = 17
elif i == 4:
current = 20

# Print numbers for the current row
for j in range(i + 1):
print(current, end=' ')
current -= (i + 1 - j)

print() # Move to the next line after each row

# Call the function to print the pattern
print_pattern()

KouseiiAdoptMeShop
Автор

def cool_pattern_function(first_nbr=2, nbr_between_iterations=6, nbr_iterations=5, nbr_steps=1):
arr = [[first_nbr]]
for i in range(0, nbr_iterations):
a =
nbr_between_iterations-=1
b = [a]
for j in range(i+1):

arr.append(b)
return arr


arr = cool_pattern_function()
for e in arr:
print(e)

bchado
Автор

row = int(input("Enter the row size : "))
diff = 7
prev = []
for i in range(row):
append(2)
for j in range(i):
prev[j]+=diff
prev[i]=prev[-1]-i
diff-=1
print(*prev)

huzzlebrothers
Автор

Chatgpt

def generate_pattern(rows):
# Initial value for the first element in the first row
start_value = 2

# List to hold all the rows
pattern = []

# Generate the rows
for i in range(1, rows + 1):
row = []
value = start_value

# Generate values for the current row
for j in range(i):
row.append(value)
value -= (j + 1) # Subtract 1, 2, 3, ...

pattern.append(row)

# Update the starting value for the next row
if i < rows: # Avoid updating for the last row
start_value += (6 - i)

return pattern

def print_pattern(pattern):
for row in pattern:
print(" ".join(map(str, row)))

# Example: Generate and print the next 6 rows (you can adjust the number)
rows_to_generate = 6
pattern =
print_pattern(pattern)

vishalsen
Автор

n = int(input())
step = 6
start = 2
for i in range(n):
temp = start
for j in range(i + 1):
if i == 0:
print(start, end=" ")
break
start = start - j
print(start, end=" ")
start = temp + (step - i)
print()

phuquyam
Автор

Counter = 0

For I in range(5):
While counter <= i:
a = 20 - 3 - i
counter += 1
b = a - i
Print(a + b)

This should work minor errors maybe but you get the point; I'm not testing it it idle

JamieSands-nn
Автор

Recursion :
Downward diagonal (first elements) generated by n_i = n_{i-1} + (7-i)
Each row extends right by n_i - k where k = 1, 2, 3, …

linchenpal
Автор

in python
8 lines code is
n=2
for i in range(6, 1, -1):
l, s=[], n
for j in range(7-i):
s=s-j
l.append(s)
print(*l)
n+=i

shivanshjee
Автор

Very simple
i in (1, 5)
j in (1, i)
-5+7i-i(i-1)/2-j(j-1)/2

AshishMishra-nuwz
Автор

make a variable diff = 6, previous = 2
loop 5 times
with every iteration
loop col, row times
print(previous-col)
previous = previous + diff - row

bhavishyasharma
Автор

current_start = 2
increment = 6 # Initial increment for row 2

for row in range(1, 6):
if row == 1:
numbers = [current_start]
else:
current_start += increment
numbers = [current_start]
current = current_start
for step in range(1, row):
current -= step
numbers.append(current)
increment -= 1

print(' '.join(map(str, numbers)))

muradmarvin
Автор

def pattern(rows):

finalMatrix = [[] for _ in range(rows)]
adding = 6
firstInt = 2

for i in range(0, rows):
term = firstInt
for j in range(0, i + 1):
term -= j
finalMatrix[i].append(term)
firstInt += adding
adding -= 1
for e in range(0, rows):
print(finalMatrix[e])
pattern(5)

lycheePi
Автор

foreach(int i in number)
Console.WriteLine(number-i);

MrRejoboGames
Автор

def generate_pattern(n):
current = 2
for row in range(1, n + 1):
values = []
val = current
for i in range(row):
values.append(val)
val -= (row - i)
print(' '.join(map(str, values)))
current += row + 5

generate_pattern(5)

Nate-ww
Автор

integer pos = 2
for i = 0 to 4 do
if i != 0 then
pos = pos + 7 - i end if
integer pos2 = pos
for a = 0 to i do
pos2 = pos2 - a
print(1, pos2)
puts(1, ' ')
end for
puts(1, '\n')
end for

hexarium
join shbcf.ru