• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 14:31
CET 20:31
KST 04:31
  • 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
SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2
Community News
BSL Season 2025 - Full Overview and Conclusion6Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)16Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7[BSL21] Non-Korean Championship - Starts Jan 105
StarCraft 2
General
Stellar Fest "01" Jersey Charity Auction SC2 All-Star Invitational: Tournament Preview Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets When will we find out if there are more tournament SC2 Spotted on the EWC 2026 list?
Tourneys
SC2 All-Star Invitational: Jan 17-18 Sparkling Tuna Cup - Weekly Open Tournament SC2 AI Tournament 2026 $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) OSC Season 13 World Championship
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Video Footage from 2005: The Birth of G2 in Spain BW General Discussion BSL Season 2025 - Full Overview and Conclusion [ASL21] Potential Map Candidates
Tourneys
[Megathread] Daily Proleagues [BSL21] Non-Korean Championship - Starts Jan 10 Small VOD Thread 2.0 Azhi's Colosseum - Season 2
Strategy
Soma's 9 hatch build from ASL Game 2 Simple Questions, Simple Answers Game Theory for Starcraft Current Meta
Other Games
General Games
Stormgate/Frost Giant Megathread Beyond All Reason Awesome Games Done Quick 2026! Nintendo Switch Thread Mechabellum
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Canadian Politics Mega-thread European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2082 users

The Big Programming Thread - Page 216

Forum Index > General Forum
Post a Reply
Prev 1 214 215 216 217 218 1032 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.
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-12 16:55:25
December 12 2012 16:47 GMT
#4301
Hey, I have a question. I understand why the following prints: MichaelLieberman. But I don't understand if I change line 4 from, x[0] + x[1] to i[0] + i[1] it prints: Mi.
Python btw.

n = ["Michael","Lieberman"]
def myFun(x):
for i in x:
return x[0] + x[1] # What happens when you change x to i?
print myFun(n)

ghrur
Profile Blog Joined May 2009
United States3786 Posts
December 12 2012 16:52 GMT
#4302
On December 13 2012 01:47 Recognizable wrote:
Hey, I have a question. I understand why the following prints: MichaelLieberman. But I don't understand if I change line 4 from, x[0] + x[1] to i[0] + i[1] it prints: Mi.

n = ["Michael","Lieberman"]
def myFun(x):
for i in x:
return x[0] + x[1] # What happens when you change x to i?
print myFun(n)



So when you change x to i, you're saying that for each element in the array, you return the first and the second element of the string i. So you return "Michael"[0] and "Michael"[1] which turns out to be "Mi". The reason it doesn't do "Li" too is because you're using return which stops the loop right there. So I think anyway.
darkness overpowering
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
December 12 2012 17:03 GMT
#4303
Ok, I understand it for strings. However I don't completely understand it for integers. Let's say we change it to n = [1,2]. I guess I understand why you can't go i[0] + i[1] because i has become a variable which loops(don't know if right word) through n=[1,2] if I am not mistaken?
LocusCoeruleus
Profile Joined June 2010
Norway32 Posts
December 12 2012 17:12 GMT
#4304
i will assume the value of all the elements in n. So in the first iteration it will be 1 and second it will be 2, so you are not mistaken.

For your first question, in the first iteration i = "Michael" and in the second iteration i = "Lieberman".
For a list A, A[2] will return the third element. For the string S, how ever, S[2] gives you the the characters from 0 to (but not including) 2.
(Reading everything above me again, I see that everything has been answered quite nicely, but whatever)
Si vis pacem, para bellum
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
December 12 2012 17:17 GMT
#4305
Ok thanks
adwodon
Profile Blog Joined September 2010
United Kingdom592 Posts
December 12 2012 21:46 GMT
#4306
Hey guys,
Two questions, both completely separate so answer either if you can

1)
I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two.

Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits.

2)
It's been a while since I did anything website related (5+ years), I'm considering setting up a personal site with a blog element, essentially to act as an both an extension for my CV and a kind of notebook / progress measure for personal projects.

Is there any kind of IDE / package I should consider using? All I remember is Dreamweaver and I have no idea if thats still useful or if there are superior / solid alternatives or as its just a small site, if I'm better off just using Notepad++ and cranking it out by hand.

I'm guessing HTML / CSS are still the main things with a splash of Javascript, but for a blog section is it reasonable to write something yourself, are there libraries / things to make this straight forward? I don't want a template site, but at the same time I don't really want to spend the next 6 months writing something with barely any functionality and full of annoying bugs, as I'd be learning every step of the way. What sort of languages would I expect to learn? I know a bit of Ruby but that's all as far as what I would consider web languages.

If there are any good resources / websites then please do share, I could probably find out a lot of this by the powers of google but I find its often best to ask in a forum as you tend to get a more well rounded answer

Thanks in advance!
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2012-12-12 22:04:04
December 12 2012 22:03 GMT
#4307
On December 13 2012 06:46 adwodon wrote:
Hey guys,
Two questions, both completely separate so answer either if you can

1)
I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two.

Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits.

2)
It's been a while since I did anything website related (5+ years), I'm considering setting up a personal site with a blog element, essentially to act as an both an extension for my CV and a kind of notebook / progress measure for personal projects.

Is there any kind of IDE / package I should consider using? All I remember is Dreamweaver and I have no idea if thats still useful or if there are superior / solid alternatives or as its just a small site, if I'm better off just using Notepad++ and cranking it out by hand.

I'm guessing HTML / CSS are still the main things with a splash of Javascript, but for a blog section is it reasonable to write something yourself, are there libraries / things to make this straight forward? I don't want a template site, but at the same time I don't really want to spend the next 6 months writing something with barely any functionality and full of annoying bugs, as I'd be learning every step of the way. What sort of languages would I expect to learn? I know a bit of Ruby but that's all as far as what I would consider web languages.

If there are any good resources / websites then please do share, I could probably find out a lot of this by the powers of google but I find its often best to ask in a forum as you tend to get a more well rounded answer

Thanks in advance!


On [1]. :


bool isPowerOfTwo(int value)
{
return value && !(value & (value - 1)); //hint: value && [...] is there just because otherwise it would consider 0 to be a power of zero
}


I'll leave it to you to figure out why this works. Should be a nice exercise in bitwise-operations.

On [2]:

As a project page, a simple plain text HTML site with some colored links that link to textual descriptions and downloads of your projects will suffice. Any person you'd want to be hired by will look for function, not form in your online CV. And for that, the only thing you really need is Notepad++

If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-12-12 22:19:33
December 12 2012 22:18 GMT
#4308
On December 13 2012 06:46 adwodon wrote:
Hey guys,
Two questions, both completely separate so answer either if you can

1)
I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two.

Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits.

2)
It's been a while since I did anything website related (5+ years), I'm considering setting up a personal site with a blog element, essentially to act as an both an extension for my CV and a kind of notebook / progress measure for personal projects.

Is there any kind of IDE / package I should consider using? All I remember is Dreamweaver and I have no idea if thats still useful or if there are superior / solid alternatives or as its just a small site, if I'm better off just using Notepad++ and cranking it out by hand.

I'm guessing HTML / CSS are still the main things with a splash of Javascript, but for a blog section is it reasonable to write something yourself, are there libraries / things to make this straight forward? I don't want a template site, but at the same time I don't really want to spend the next 6 months writing something with barely any functionality and full of annoying bugs, as I'd be learning every step of the way. What sort of languages would I expect to learn? I know a bit of Ruby but that's all as far as what I would consider web languages.

If there are any good resources / websites then please do share, I could probably find out a lot of this by the powers of google but I find its often best to ask in a forum as you tend to get a more well rounded answer

Thanks in advance!


1)
Theres a few ways I can think to do this, but I like your way, so I'm going to use it.
in C:

int ispow2(int num)
{
while(! (num%2)) num=num>>1; //slide the number over to the first bit
return !(num>>1); //if its the only bit in the number, then the number is a power of 2
}

Or using a mask

int ispow2(int num)
{
int mask = 1;
while(mask) //this works because bitshifting using << will bitshift all the way to 0 when overflowed.
if(!(mask ^ num)) return true;
else mask = mask << 1;

return false;
}


EDIT: oooo I like heishe's implementation way better.
2) Wordpress has become the defacto standard for blogs. You can also check out Svbtle, which looks pretty cool. It's way easier than it ever has been to set up a personal blog.
Any sufficiently advanced technology is indistinguishable from magic
tofucake
Profile Blog Joined October 2009
Hyrule19189 Posts
December 12 2012 22:18 GMT
#4309
web design IDEs are the devil
Liquipediaasante sana squash banana
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
December 12 2012 22:20 GMT
#4310
On December 13 2012 07:18 tofucake wrote:
web design IDEs are the devil

oh tofucake, its always 'X' is the devil with you. Tell us how you really feel about web design IDE's ^_^
Any sufficiently advanced technology is indistinguishable from magic
tofucake
Profile Blog Joined October 2009
Hyrule19189 Posts
December 12 2012 22:25 GMT
#4311
They spit out barely manageable code based on tables and frames. Trying to tweak the layout is basically impossible. Forget about adding functionality and different screens (ie: doing anything a modern website would want to do) with PHP or ASP or even javascript. AJAX confuses every single one of them as well.

IDEs are responsible for sites like this
Liquipediaasante sana squash banana
adwodon
Profile Blog Joined September 2010
United Kingdom592 Posts
December 12 2012 22:36 GMT
#4312
On December 13 2012 07:03 heishe wrote:
On [1]. :


bool isPowerOfTwo(int value)
{
return value && !(value & (value - 1)); //hint: value && [...] is there just because otherwise it would consider 0 to be a power of zero
}


I'll leave it to you to figure out why this works. Should be a nice exercise in bitwise-operations.



Looks shiney, I'll have a better look at it tomorrow (its about my bed time right now!).

On December 13 2012 07:18 RoyGBiv_13 wrote:
2) Wordpress has become the defacto standard for blogs. You can also check out Svbtle, which looks pretty cool. It's way easier than it ever has been to set up a personal blog.


Appreciate the info, I'll probably start with something simple and expand from there, Svbtle looks interesting o.O

On December 13 2012 07:18 tofucake wrote:
web design IDEs are the devil


I do remember being told many years ago that things like Dreamweaver, whilst having their uses were generally for people with no interest or talent for actual code and also had a tendency to spew out rather unpleasant messes, I'm guessing things haven't changed in that sense much then!

jjwhg
Profile Blog Joined October 2012
United States155 Posts
December 12 2012 23:28 GMT
#4313
On December 13 2012 06:46 adwodon wrote:
I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two.

Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits.


While this is probably overkill: In modern x86 CPUs there's actually an instruction that counts the number of bits set in a word, also known as the population count. The following GCC-specific C code

int power_of_two(unsigned int x)
{
return __builtin_popcount(x) == 1;
}


compiles to 5 branch-free instructions on my machine (be sure to build with "-msse4.2")

power_of_two:
popcntl %edi, %edi
xorl %eax, %eax
cmpl $1, %edi
sete %al
ret


which I think is just about as efficient as you're going to get.
♥ Bisu ♥
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
December 13 2012 01:23 GMT
#4314
On December 13 2012 07:18 tofucake wrote:
web design IDEs are the devil


I wholeheartedly agree.

For a blog, just use wordpress. Doing it yourself is a waste of time.
There is nothing wrong without using it and some existing theme, what matters in the end is the content anyways.
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2012-12-13 14:18:08
December 13 2012 14:16 GMT
#4315
Question: Given an ordinary 16-bit number, what's the fastest way to count the number of all consecutive 1s from the left? I've looked at the graphics.stanford site, but I can't apply anything.

E.g. 1110101011000101 should return 3; 1111100100100111... should return 5, etc.

Checking single bits is trivial, but it's also incredibly slow.

So far the only thing I've tried are lookup tables, which are even slower than looping through all bits manually (probably because a lookup table doesn't fit into the cache at all, resulting in tons of cache misses)
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2589 Posts
Last Edited: 2012-12-13 14:32:43
December 13 2012 14:21 GMT
#4316
Why is checking single bits incredibly slow? Can't you just do sixteen bitwise shifts and use two variables to keep track of your current and max count of consecutive 1s?

Edit: Clarify what I mean with a bit of pseudocode


val = 0111100111010111;
max = 0;
cur = 0;
for(i = 0; i < 16; i++) {
if(val & 1) {
cur++;
}
else {
if(cur > max) max = cur;
cur = 0;
}

val >> 1; //Bitwise shift to the right by one
}


Oh, I see that you asked for counting from the left. The result is the same regardless of which direction you count, but if you want to start from the left, just use "val & 0b1000000000000000" and "val << 1" instead.
The frumious Bandersnatch
heishe
Profile Blog Joined June 2009
Germany2284 Posts
December 13 2012 15:13 GMT
#4317
On December 13 2012 23:21 AmericanUmlaut wrote:
Why is checking single bits incredibly slow? Can't you just do sixteen bitwise shifts and use two variables to keep track of your current and max count of consecutive 1s?


I already have a version that you're suggesting, but that piece of code is executed roughly 155 million times per second, which is why potentially 16 more loop iterations are incredibly slow.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2589 Posts
December 13 2012 15:19 GMT
#4318
Hmm... Is there a specific threshhold you're looking for, or do you really need the maximum number?
The frumious Bandersnatch
gyth
Profile Blog Joined September 2009
657 Posts
Last Edited: 2012-12-13 17:24:05
December 13 2012 17:23 GMT
#4319
There is probably an assembly instruction to do what you're looking for, or its complement.
http://en.wikipedia.org/wiki/Find_first_set
The plural of anecdote is not data.
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2012-12-13 17:36:46
December 13 2012 17:35 GMT
#4320
On December 14 2012 02:23 gyth wrote:
There is probably an assembly instruction to do what you're looking for, or its complement.
http://en.wikipedia.org/wiki/Find_first_set


Well, I'm already using bsf/bsr in another part of the program, problem is as far as I know there's only the instruction that starts from the LSB and counts the first found set bit "starting from the right". If there was a similar instruction that would do the same thing but started "from the left", I could just invert the 16 bit and execute that instruction on it. But so far, I haven't found anything.

(bsf and bsr produce the same results, they just start out differently.).

Essentially bsf and bsr count trailing zeroes. I need something that counts leading zeroes.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
Prev 1 214 215 216 217 218 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 29m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 646
IndyStarCraft 188
Vindicta 32
JuggernautJason32
StarCraft: Brood War
Calm 2276
Shuttle 696
Mini 35
910 29
Movie 17
Dota 2
Gorgc7555
qojqva3928
Counter-Strike
byalli2931
fl0m2765
Heroes of the Storm
Liquid`Hasu384
Other Games
FrodaN6971
Grubby3640
Liquid`RaSZi2699
summit1g2611
B2W.Neo991
crisheroes327
Harstem280
ToD194
ArmadaUGS145
Mew2King17
mouzStarbuck15
Railgan1
Organizations
Other Games
gamesdonequick2600
StarCraft 2
ComeBackTV 1518
Other Games
EGCTV1298
StarCraft 2
angryscii 22
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• HeavenSC 31
• Reevou 3
• Kozan
• Laughngamez YouTube
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• FirePhoenix14
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Jankos2966
• TFBlade782
Other Games
• imaqtpie2207
• Shiphtur268
Upcoming Events
BSL 21
29m
Bonyth vs Sziky
Mihu vs QiaoGege
Sziky vs XuanXuan
eOnzErG vs QiaoGege
Mihu vs DuGu
Dewalt vs Bonyth
IPSL
29m
Dewalt vs Sziky
Replay Cast
13h 29m
Wardi Open
16h 29m
Monday Night Weeklies
21h 29m
OSC
1d 15h
The PondCast
2 days
OSC
2 days
Big Brain Bouts
4 days
Serral vs TBD
BSL 21
5 days
[ Show More ]
BSL 21
6 days
Liquipedia Results

Completed

Escore Tournament S1: W4
Big Gabe Cup #3
NA Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
OSC Championship Season 13
Underdog Cup #3
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025

Upcoming

Escore Tournament S1: W5
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Nations Cup 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
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 © 2026 TLnet. All Rights Reserved.