1234
123
12
1
12
123
1234
1
11
111
1111
1
123
12
12345
123
1234567
1234
What have you tried and what is your expected result?
Best regards,
Tomas
Hi Tomas , i tried for loops for doing same but unfortunately , it doesn’t work well in corona.Also ,i don’t know how to use pre increments in corona .
It simply prints nos. in first line and then nothing happens.
Search for same online , but no results for same.
You should probably Google “for loop lua” instead of Corona:
http://www.lua.org/pil/4.3.4.html
A basic for loop:
for i=1, 10, 1 do print("i:", i) end
Your first problem might be solved like this:
local s = "" for i = 1, 4, 1 do s = s .. i print(s) end
Thanks for you reply , but i already worked on same loop , no. of times earlier , it simply prints no. based on increment or decrement values and my problem is totally different from same.
1
2
3
4
5
6
7
8
9
10
@Bindra,
Hi. I’m puzzling over your post title and the example you gave…
Your post title does not produce the outputs you listed in the body of your post.
Can you point us to an alternate solution/algorithm name/something besides the pattern?
You’ve listed three different patters with no basis for how they are produced. i.e. What are the rules for producing outputs like that. They look a bit arbitrary to me, but maybe they are a produced by a pattern generator I am not remembering.
PS - Lua does not support operator based pre-increment/decrement like C++ or other languages.
(I forgot to ask, but how does this apply to game development and Corona? This seems more like a learning-Lua thing or homework.)
I came up with functions to produce your first two pattern examples,
local function doPatt1( max ) for i = max, 2, -1 do local out = "" for k = 1, i do out = out .. tostring( k ) end print(out) end print(1) for i = 2, max do local out = "" for k = 1, i do out = out .. tostring( k ) end print(out) end end local function doPatt2( max ) for i = 1, max do local out = "" for k = 1, i do out = out .. "1" end print(out) end end doPatt1(4) print("\n=====================================\n") doPatt2(4)
The third pattern:
1
123
12
12345
123
1234567
1234
seems to have these rules:
I’m sure I could puzzle this out after some time, but this will likely involve a few functions or loops in loops to do the work.
Missing rule: Stop after N iterations or after max value?
What have you tried and what is your expected result?
Best regards,
Tomas
Hi Tomas , i tried for loops for doing same but unfortunately , it doesn’t work well in corona.Also ,i don’t know how to use pre increments in corona .
It simply prints nos. in first line and then nothing happens.
Search for same online , but no results for same.
You should probably Google “for loop lua” instead of Corona:
http://www.lua.org/pil/4.3.4.html
A basic for loop:
for i=1, 10, 1 do print("i:", i) end
Your first problem might be solved like this:
local s = "" for i = 1, 4, 1 do s = s .. i print(s) end
Thanks for you reply , but i already worked on same loop , no. of times earlier , it simply prints no. based on increment or decrement values and my problem is totally different from same.
1
2
3
4
5
6
7
8
9
10
@Bindra,
Hi. I’m puzzling over your post title and the example you gave…
Your post title does not produce the outputs you listed in the body of your post.
Can you point us to an alternate solution/algorithm name/something besides the pattern?
You’ve listed three different patters with no basis for how they are produced. i.e. What are the rules for producing outputs like that. They look a bit arbitrary to me, but maybe they are a produced by a pattern generator I am not remembering.
PS - Lua does not support operator based pre-increment/decrement like C++ or other languages.
(I forgot to ask, but how does this apply to game development and Corona? This seems more like a learning-Lua thing or homework.)
I came up with functions to produce your first two pattern examples,
local function doPatt1( max ) for i = max, 2, -1 do local out = "" for k = 1, i do out = out .. tostring( k ) end print(out) end print(1) for i = 2, max do local out = "" for k = 1, i do out = out .. tostring( k ) end print(out) end end local function doPatt2( max ) for i = 1, max do local out = "" for k = 1, i do out = out .. "1" end print(out) end end doPatt1(4) print("\n=====================================\n") doPatt2(4)
The third pattern:
1
123
12
12345
123
1234567
1234
seems to have these rules:
I’m sure I could puzzle this out after some time, but this will likely involve a few functions or loops in loops to do the work.
Missing rule: Stop after N iterations or after max value?