Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Baseus PI LITE INDOOR CAMERA
ErMurazor
Updated:
Yesterday at 12:26 PM
Ad icon
Colombo
Hard Disk For Sale
mazza
Updated:
Saturday at 10:23 PM
land for sale
justasking
Updated:
Saturday at 9:32 AM
AMD AM 5 Ryzen setup
prabodhamadusanka
Updated:
Thursday at 12:56 PM
Gampaha
ACER OKW223 Wired RGB Keyboard
chint
Updated:
Thursday at 10:17 AM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
The Simplest Math Problem No One Can Solve
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="olu bakka" data-source="post: 27973185" data-attributes="member: 369164"><p>අම්මටහුඩු මාත් ඕක බලල python code එකක් ගැහුව</p><p></p><p>මේ වගේ output එකක් ගන්න පුලුවන්</p><p></p><p>[CODE]Enter from number: 5</p><p>Enter to number: 10</p><p>+------+------------+-------+</p><p>| Seed | Max Number | Steps |</p><p>+------+------------+-------+</p><p>| 5 | 16 | 5 |</p><p>| 6 | 16 | 8 |</p><p>| 7 | 52 | 16 |</p><p>| 8 | 8 | 3 |</p><p>| 9 | 52 | 19 |</p><p>| 10 | 16 | 6 |</p><p>+------+------------+-------+</p><p>Maximum number reached in the sequence = 52 (Seed number = [7, 9])</p><p>Maxiumum steps = 19 (Seed number = [9])[/CODE]</p><p></p><p>[CODE=python]# Collatz Conjucture</p><p># Info - https://www.youtube.com/watch?v=094y1Z2wpJg&ab_channel=Veritasium</p><p>from tabulate import tabulate</p><p></p><p>def calculation (n1, n2):</p><p> i = 0</p><p> nlist = []</p><p> for x in range(n1, n2+1):</p><p> maxn = 0</p><p> s = 0</p><p> nlist.append([])</p><p> nlist[i].append(x)</p><p> if x % 10000 == 0:</p><p> print(round(((x - n1) / (n2 - n1)) * 100, 2), "%")</p><p> while True:</p><p> #print(int(x), end=" , ")</p><p> if x > maxn:</p><p> maxn = x</p><p></p><p> if x == 1:</p><p> break</p><p> else:</p><p> s += 1</p><p> if x % 2 == 1:</p><p> x = (3*x) + 1</p><p> else:</p><p> x = x//2</p><p> nlist[i].append(maxn)</p><p> nlist[i].append(s)</p><p> i += 1</p><p></p><p> seqmaxn = 0</p><p> maxnseed = []</p><p> seqmaxs = 0</p><p> maxsseed = []</p><p> for q in nlist:</p><p> if q[0] % 10000 == 0:</p><p> print(round(50 + (((q[0] - n1) / (n2 - n1)) * 50), 2), "%")</p><p> if q[1] == seqmaxn:</p><p> maxnseed.append(q[0])</p><p> elif q[1] > seqmaxn:</p><p> seqmaxn = q[1]</p><p> maxnseed.clear()</p><p> maxnseed.append(q[0])</p><p></p><p> if q[2] == seqmaxs:</p><p> maxsseed.append(q[0])</p><p> elif q[2] > seqmaxs:</p><p> seqmaxs = q[2]</p><p> maxsseed.clear()</p><p> maxsseed.append(q[0])</p><p> print(tabulate(nlist, headers=["Seed", "Max Number", "Steps"], tablefmt="pretty"))</p><p> print(f"Maximum number reached in the sequence = {seqmaxn} (Seed number = {maxnseed})\nMaxiumum steps = {seqmaxs} (Seed number = {maxsseed})\n")</p><p></p><p></p><p>while True:</p><p> num1 = int(input("Enter from number: "))</p><p> num2 = int(input("Enter to number: "))</p><p></p><p> calculation(num1, num2)[/CODE]</p><p></p><p>PS: කෝඩින් වල professional practices දන්නෙ නෑ යන්තන් අතපත ගානව විතරයි. ඒක හින්ද සමාවෙන්න ඕනෙ ගොන් පාට් තිබ්බොත්</p></blockquote><p></p>
[QUOTE="olu bakka, post: 27973185, member: 369164"] අම්මටහුඩු මාත් ඕක බලල python code එකක් ගැහුව මේ වගේ output එකක් ගන්න පුලුවන් [CODE]Enter from number: 5 Enter to number: 10 +------+------------+-------+ | Seed | Max Number | Steps | +------+------------+-------+ | 5 | 16 | 5 | | 6 | 16 | 8 | | 7 | 52 | 16 | | 8 | 8 | 3 | | 9 | 52 | 19 | | 10 | 16 | 6 | +------+------------+-------+ Maximum number reached in the sequence = 52 (Seed number = [7, 9]) Maxiumum steps = 19 (Seed number = [9])[/CODE] [CODE=python]# Collatz Conjucture # Info - https://www.youtube.com/watch?v=094y1Z2wpJg&ab_channel=Veritasium from tabulate import tabulate def calculation (n1, n2): i = 0 nlist = [] for x in range(n1, n2+1): maxn = 0 s = 0 nlist.append([]) nlist[i].append(x) if x % 10000 == 0: print(round(((x - n1) / (n2 - n1)) * 100, 2), "%") while True: #print(int(x), end=" , ") if x > maxn: maxn = x if x == 1: break else: s += 1 if x % 2 == 1: x = (3*x) + 1 else: x = x//2 nlist[i].append(maxn) nlist[i].append(s) i += 1 seqmaxn = 0 maxnseed = [] seqmaxs = 0 maxsseed = [] for q in nlist: if q[0] % 10000 == 0: print(round(50 + (((q[0] - n1) / (n2 - n1)) * 50), 2), "%") if q[1] == seqmaxn: maxnseed.append(q[0]) elif q[1] > seqmaxn: seqmaxn = q[1] maxnseed.clear() maxnseed.append(q[0]) if q[2] == seqmaxs: maxsseed.append(q[0]) elif q[2] > seqmaxs: seqmaxs = q[2] maxsseed.clear() maxsseed.append(q[0]) print(tabulate(nlist, headers=["Seed", "Max Number", "Steps"], tablefmt="pretty")) print(f"Maximum number reached in the sequence = {seqmaxn} (Seed number = {maxnseed})\nMaxiumum steps = {seqmaxs} (Seed number = {maxsseed})\n") while True: num1 = int(input("Enter from number: ")) num2 = int(input("Enter to number: ")) calculation(num1, num2)[/CODE] PS: කෝඩින් වල professional practices දන්නෙ නෑ යන්තන් අතපත ගානව විතරයි. ඒක හින්ද සමාවෙන්න ඕනෙ ගොන් පාට් තිබ්බොත් [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom