• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 20:48
CEST 02:48
KST 09:48
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Maestros of the Game: Week 1/Play-in Preview9[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (August 25-31): Clem's Last Straw?24Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris46Weekly Cups (Aug 11-17): MaxPax triples again!15Weekly Cups (Aug 4-10): MaxPax wins a triple6
StarCraft 2
General
Weekly Cups (August 25-31): Clem's Last Straw? Geoff 'iNcontroL' Robinson has passed away #1: Maru - Greatest Players of All Time Maestros of the Game: Week 1/Play-in Preview Weekly Cups (Aug 11-17): MaxPax triples again!
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament Maestros of The Game—$20k event w/ live finals in Paris Monday Nights Weeklies LiuLi Cup - September 2025 Tournaments 🏆 GTL Season 2 – StarCraft II Team League
Strategy
Custom Maps
External Content
Mutation # 489 Bannable Offense Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies
Brood War
General
BW General Discussion ASL20 General Discussion BGH Auto Balance -> http://bghmmr.eu/ No Rain in ASL20? Starcraft at lower levels TvP
Tourneys
[Megathread] Daily Proleagues Is there English video for group selection for ASL [ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined!
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Mechabellum Teeworlds - online game General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Canadian Politics Mega-thread YouTube Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 629 users

The Big Programming Thread - Page 223

Forum Index > General Forum
Post a Reply
Prev 1 221 222 223 224 225 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
December 26 2012 20:49 GMT
#4441
On December 27 2012 05:32 Perscienter wrote:
And please don't call functions in a print statement.

Why?
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-26 20:53:53
December 26 2012 20:49 GMT
#4442
On December 27 2012 05:45 Perscienter wrote:
Use only lower case characters, underscores and numbers for function names.

A style guide for Python can be found here: http://www.python.org/dev/peps/pep-0008/

It covers many aspects of formatting and how to name stuff.

Calling is not renaming it. You define a function and you can call it. That's applying it. The code, which is included in your function is not applied until you call or apply the function. In your example, it would be done after the while loop, but can't reach the end of it, because n never reaches 100, since you don't call the function inside the while loop.

It will become very clear to you, I have no doubt.


Thank you. I figured it out.
fibo = [1,2]
def create_fibo(x):
while len(fibo) < 100:
z = x[-1] + x[-2]
fibo.append(z)
create_fibo(fibo)
print fibo


Finally! I feel like such an idiot for not figuring that out on myself tho haha. But your explanation made it all very clear
LunaSea
Profile Joined October 2011
Luxembourg369 Posts
Last Edited: 2012-12-26 20:52:15
December 26 2012 20:50 GMT
#4443
I just changed your code a little bit and it works :

n = [1, 2]
def fibonnaci(n, x):
while len(n) < 100:
z = x[-1] + x[-2]
n.append(z)
return n
print(fibonnaci(n, n))


If you want to do it without a loop, a recursive function would also work :


n = [1, 2]
def fibonnaci(n, x):
if len(n) < 100:
z = x[-1] + x[-2]
n.append(z)
return fibonnaci(n, x)
return n
print(fibonnaci(n, n))


The reason I added parenthesis around after the print method is because it changed from Python 2.7 to Python 3.x.
"Your f*cking wrong, but I respect your opinion" --Day[9]
Fwmeh
Profile Joined April 2008
1286 Posts
December 26 2012 21:04 GMT
#4444
Now do it in time log(n) =P
A parser for things is a function from strings to lists of pairs of things and strings
Perscienter
Profile Joined June 2010
957 Posts
December 26 2012 21:05 GMT
#4445
On December 27 2012 05:49 delHospital wrote:
Show nested quote +
On December 27 2012 05:32 Perscienter wrote:
And please don't call functions in a print statement.

Why?

Well, I take that back. I'm just not used to it. In the Python shell it wouldn't matter.

But it only makes sense, when the function returns a value. So a generalized rejection of printing functions would be wrong. It does make sense, when functions return value and you want to print something, for instance in a console program.
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
December 26 2012 21:21 GMT
#4446
On December 27 2012 06:04 Fwmeh wrote:
Now do it in time log(n) =P


?
LunaSea
Profile Joined October 2011
Luxembourg369 Posts
Last Edited: 2012-12-26 21:45:56
December 26 2012 21:44 GMT
#4447
On December 27 2012 06:21 Recognizable wrote:
Show nested quote +
On December 27 2012 06:04 Fwmeh wrote:
Now do it in time log(n) =P


?


He's referring to the "big O" notation and algorithm complexity calculations.

Here is a pretty good post on the subject from Stackoverflow :

--> http://stackoverflow.com/questions/487258/plain-english-explanation-of-big-o
"Your f*cking wrong, but I respect your opinion" --Day[9]
Shenghi
Profile Joined August 2010
167 Posts
December 26 2012 22:41 GMT
#4448
On December 27 2012 06:04 Fwmeh wrote:
Now do it in time log(n) =P

Why do it in O(log(n)) when there's a closed form formula to do it in O(1)?
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
Fwmeh
Profile Joined April 2008
1286 Posts
December 26 2012 22:50 GMT
#4449
On December 27 2012 07:41 Shenghi wrote:
Show nested quote +
On December 27 2012 06:04 Fwmeh wrote:
Now do it in time log(n) =P

Why do it in O(log(n)) when there's a closed form formula to do it in O(1)?

1) The closed formula will involve floats which are tricky
2) The closed formula will involve roots depending on the size, and roots are actually not in O(1), so the solution will not either
3) It is not very interesting to do it like that
^^
A parser for things is a function from strings to lists of pairs of things and strings
Shenghi
Profile Joined August 2010
167 Posts
December 26 2012 22:56 GMT
#4450
On December 27 2012 07:50 Fwmeh wrote:
Show nested quote +
On December 27 2012 07:41 Shenghi wrote:
On December 27 2012 06:04 Fwmeh wrote:
Now do it in time log(n) =P

Why do it in O(log(n)) when there's a closed form formula to do it in O(1)?

1) The closed formula will involve floats which are tricky
2) The closed formula will involve roots depending on the size, and roots are actually not in O(1), so the solution will not either
3) It is not very interesting to do it like that
^^

1) That's part of the challenge.
2) They are always the same roots (√5).
3) True. =]
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
Fwmeh
Profile Joined April 2008
1286 Posts
December 26 2012 23:21 GMT
#4451
Well ok, you have to calculate (1+-√5)^n, and I don't think you can do that in constant time.
A parser for things is a function from strings to lists of pairs of things and strings
Shenghi
Profile Joined August 2010
167 Posts
December 28 2012 03:47 GMT
#4452
On December 27 2012 08:21 Fwmeh wrote:
Well ok, you have to calculate (1+-√5)^n, and I don't think you can do that in constant time.

I think I agree. If I recall correctly, the complexity of a^b is O(log(b)).
People are not born stupid, they choose to be stupid. If you made that choice, please change your mind.
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-28 19:58:56
December 28 2012 19:42 GMT
#4453
If you have a 2 dimensional list in Python. Why does len(list) return the length of the grid in the x-coordinate direction and len(list[0]) the length of the grid in the y-coordinate direction?
Here is an example of such a list.
O O O O O
O O O O O
O O O O O
Zeke50100
Profile Blog Joined February 2010
United States2220 Posts
December 28 2012 19:59 GMT
#4454
On December 29 2012 04:42 Recognizable wrote:
If you have a 2 dimensional list in Python. Why does len(list) return the length of the row(x-coordinate) and len(list[0]) the length of the column(y-coordinate)?


A 2 dimensional list is really just a list of lists.

The first dimension specifies which list you wish to access, and the second dimension specifies the term in the list. Using "row" and "column" is somewhat misleading because rows and columns are just visual representations (and not actually what's happening under the hood).

len(myList) will give you how many lists there are (in other words, the number of "rows") because myList is a list just like every other list - it just happens to be that the items in the list are lists themselves. Similarly, myList[0] will access list 0 stored in myList, and myList[1] will access list 1 in myList.

len(myList[0]) will give you how many terms are in the list stored in myList[0] (or the number of "columns" in myList, if myList is rectangular - myList[0] can be a list of numbers, puppies, cookies, etc.). When you type in something like myList[0][1], you're saying "What is element 1 in the list, myList[0]?"
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-28 20:22:37
December 28 2012 20:14 GMT
#4455
nvm, I understand thanks
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
December 29 2012 08:43 GMT
#4456
Hello. I wanted to post something useful for those of you guys who are learning how to program. It is called a "Kata". A kata is basically an exercise that refines your programming skills. More importantly, when transitioning to a new language, you can program your katas in that language to get an understanding of how the program in that language. Rather than shifting through books re-learning the syntax, a kata will help you find the important aspects of that programming language.

One great kata is that of the bowling game kata, which can be found here:
http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata

There are several other katas on the internet that you can find - I just wanted to introduce the idea to you guys. Aside from katas, a lot of you come in asking for projects and things to practice programming on. CodeChef has a really great website for this. It splits up projects based on ranking (easy/medium/hard.. etc). As a bonus, there are monthly challenges, you can compare the memory usage and runtime of the programming languages used, and look at other peoples successful code. Link Here:
http://www.codechef.com/

It's important to try and program every day to get good at it! Happy programming guys. And happy new year!
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
December 29 2012 17:59 GMT
#4457
On December 29 2012 17:43 Abductedonut wrote:
Hello. I wanted to post something useful for those of you guys who are learning how to program. It is called a "Kata". A kata is basically an exercise that refines your programming skills. More importantly, when transitioning to a new language, you can program your katas in that language to get an understanding of how the program in that language. Rather than shifting through books re-learning the syntax, a kata will help you find the important aspects of that programming language.

One great kata is that of the bowling game kata, which can be found here:
http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata

There are several other katas on the internet that you can find - I just wanted to introduce the idea to you guys. Aside from katas, a lot of you come in asking for projects and things to practice programming on. CodeChef has a really great website for this. It splits up projects based on ranking (easy/medium/hard.. etc). As a bonus, there are monthly challenges, you can compare the memory usage and runtime of the programming languages used, and look at other peoples successful code. Link Here:
http://www.codechef.com/

It's important to try and program every day to get good at it! Happy programming guys. And happy new year!


Thanks, I'll look into this. Almost finished LPTHW and Codeacademy, and I'm stuck on project euler problem 3
AmericanUmlaut
Profile Blog Joined November 2010
Germany2577 Posts
December 29 2012 18:47 GMT
#4458
On December 30 2012 02:59 Recognizable wrote:
Show nested quote +
On December 29 2012 17:43 Abductedonut wrote:
Hello. I wanted to post something useful for those of you guys who are learning how to program. It is called a "Kata". A kata is basically an exercise that refines your programming skills. More importantly, when transitioning to a new language, you can program your katas in that language to get an understanding of how the program in that language. Rather than shifting through books re-learning the syntax, a kata will help you find the important aspects of that programming language.

One great kata is that of the bowling game kata, which can be found here:
http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata

There are several other katas on the internet that you can find - I just wanted to introduce the idea to you guys. Aside from katas, a lot of you come in asking for projects and things to practice programming on. CodeChef has a really great website for this. It splits up projects based on ranking (easy/medium/hard.. etc). As a bonus, there are monthly challenges, you can compare the memory usage and runtime of the programming languages used, and look at other peoples successful code. Link Here:
http://www.codechef.com/

It's important to try and program every day to get good at it! Happy programming guys. And happy new year!


Thanks, I'll look into this. Almost finished LPTHW and Codeacademy, and I'm stuck on project euler problem 3

That's the one where you need to get the largest prime factor of a really big number, right?

Some suggestions to help you on your way:

+ Show Spoiler +

1. Depending on the language you're using, you'll probably need a library to store the number you're factoring.
2. Do you know how to get the prime factors of a number by hand? If so, you just need an algorithm that does the same thing, then you return the largest result.
3. Performance hint: Instead of performing division on a big number, you can determine whether a number is divisible by 2 by looking just at the last bit.
The frumious Bandersnatch
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
December 29 2012 19:04 GMT
#4459
Is a library the same thing as a list? Can't find it on google.
windzor
Profile Joined October 2010
Denmark1013 Posts
December 29 2012 19:05 GMT
#4460
On December 30 2012 04:04 Recognizable wrote:
Is a library the same thing as a list? Can't find it on google.


In what context? My guess is, that in yours it's a no.
Yeah
Prev 1 221 222 223 224 225 1031 Next
Please log in or register to reply.
Live Events Refresh
PiGosaur Monday
00:00
#47
SteadfastSC153
CranKy Ducklings118
rockletztv 29
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SteadfastSC 153
Nina 5
StarCraft: Brood War
Artosis 853
sSak 285
NaDa 29
Purpose 11
yabsab 4
Dota 2
monkeys_forever945
Counter-Strike
Fnx 1402
taco 325
Super Smash Bros
hungrybox287
Other Games
summit1g5975
Grubby1882
shahzam710
C9.Mang0474
Maynarde216
ViBE190
Mew2King79
Trikslyr73
JuggernautJason16
tarik_tv0
Organizations
Other Games
gamesdonequick763
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• blackmanpl 19
• HerbMon 6
• sM.Zik 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Scarra1327
• imaqtpie1173
Upcoming Events
LiuLi Cup
10h 12m
Replay Cast
23h 12m
The PondCast
1d 9h
RSL Revival
1d 9h
Maru vs SHIN
MaNa vs MaxPax
Maestros of the Game
1d 16h
OSC
2 days
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
2 days
Reynor vs Astrea
Classic vs sOs
Maestros of the Game
2 days
BSL Team Wars
2 days
Team Bonyth vs Team Dewalt
CranKy Ducklings
3 days
[ Show More ]
RSL Revival
3 days
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
3 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
Maestros of the Game
3 days
[BSL 2025] Weekly
3 days
RSL Revival
4 days
Cure vs Bunny
Creator vs Zoun
Maestros of the Game
4 days
BSL Team Wars
4 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
5 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 2
SEL Season 2 Championship
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

LASL Season 20
2025 Chongqing Offline CUP
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
EC S1
BLAST Rivals Fall 2025
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.