repl.it
@MinecraftMrGabe/

how do you lua

Lua

No description

fork
loading
Files
  • main.lua
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function pe1()
sum = 0
for x = 0,999 do
  if x%5==0 or x%3==0 then
    sum = sum+x
  end
end
print(sum)
end

function pe2()
sum = 0
last = 1
fib = 1
while fib<4000000 do
  if fib%2==0 then
    sum = sum+fib
  end
  a = last
  last = fib
  fib = fib+a
end
print(sum)
end

function pe3()--: find lagest prime factor
math = require "math"

function isprimev2(x)
  for n = 2,math.sqrt(x) do
    if x%n==0 then
      return false
    end
  end
  return true
end
function isfac(x,n)
  return x%n==0
end
lpf = 0
for x = 0,600851475143^(1/2) do
  if isfac(600851475143,x) then
    if isprimev2(x) then
      lpf = x
    end
  end
end
print('final')
print(lpf)
end

function pe4()
lpn = 0 
for x = 100,999 do
  for y = 100,999 do
    z = tostring(x*y)
    if z == string.reverse(z) then
      if x*y>lpn then
        lpn = x*y
      end
    end
  end
end
print(lpn)
end

function pe5()
sedn = 1
temp = 1
--sedn = smallest evenly divisible number
x = 1
while(x<=20) do
  if sedn%x==0 then
    sedn = sedn
    x=x+1
    temp = sedn
  else
    sedn = sedn+temp
  end
end
print('sedn:', sedn)
end
--pe6 is already done

function pe7()
primes = 0
try = 1
function isprime(x)
  for n=2,math.sqrt(x) do
    if x%n==0 then
      return false
    end
  end
  return true
end
while(primes<10001) do
  try = try+1
  if isprime(try) then
    primes=primes+1
  end
end
print(try)
end

function pe9()
for a = 1 , 1000 do
  for b= 1, 1000 do
    for c=1,1000 do
      if a<b and b<c then
        if a+b+c==1000 then
          if a*a+b*b==c*c then
            print(a*b*c)
          end
        end
      end
    end
  end
end
end

function pe10()
function isprime(x)
  for n=2,math.sqrt(x) do
    if x%n==0 then
      return false
    end
  end
  return true
end
sum = 0
for x = 1,1000000 do
  x = x*2-1
  if isprime(x) then
    sum = sum+x
  end
end
print(sum)
end
pe10()