File tree Expand file tree Collapse file tree 3 files changed +39
-7
lines changed
Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Original file line number Diff line number Diff line change 1- local count = 0 ;
2- for i = 0 , 100 , 1 do
3- local x = function ()
4- i = i + 1 ;
5- end
6- x ();
1+ local arr = {}
2+ for i = 1 , 100 do
3+ local x ;
4+ x = (x or 1 ) + i ;
5+ arr [i ] = function ()
6+ return x ;
7+ end
78end
8- print (count );
9+
10+ for i , func in ipairs (arr ) do
11+ print (func ())
12+ end
Original file line number Diff line number Diff line change 1+ -- Print the fibonacci sequence
2+ local function fibonacci (max )
3+ local a , b = 0 , 1
4+ while a < max do
5+ print (a )
6+ a , b = b , a + b
7+ end
8+ end
9+
10+ fibonacci (1000 )
Original file line number Diff line number Diff line change 1+ -- print first n primes
2+ local function primes (n )
3+ local function isPrime (n )
4+ for i = 2 , math.sqrt (n ) do
5+ if n % i == 0 then
6+ return false
7+ end
8+ end
9+ return true
10+ end
11+ for i = 2 , n do
12+ if isPrime (i ) then
13+ print (i )
14+ end
15+ end
16+ end
17+
18+ primes (20 )
You can’t perform that action at this time.
0 commit comments