• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:52
CEST 15:52
KST 22:52
  • 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
[ASL21] Ro24 Preview Pt2: News Flash8[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy15ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book20
Community News
Weekly Cups (March 23-29): herO takes triple6Aligulac acquired by REPLAYMAN.com/Stego Research7Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool49Weekly Cups (March 9-15): herO, Clem, ByuN win4
StarCraft 2
General
Team Liquid Map Contest #22 - Presented by Monster Energy Aligulac acquired by REPLAYMAN.com/Stego Research Weekly Cups (March 23-29): herO takes triple What mix of new & old maps do you want in the next ladder pool? (SC2) herO wins SC2 All-Star Invitational
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Season 4 announced for March-April StarCraft Evolution League (SC Evo Biweekly) WardiTV Mondays World University TeamLeague (500$+) | Signups Open
Strategy
Custom Maps
[M] (2) Frigid Storage Publishing has been re-enabled! [Feb 24th 2026]
External Content
Mutation # 519 Inner Power The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat
Brood War
General
ASL21 General Discussion A cwal.gg Extension - Easily keep track of anyone Behind the scenes footage of ASL21 Group E BW General Discussion BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL21] Ro24 Group E 🌍 Weekly Foreign Showmatches [ASL21] Ro24 Group F Azhi's Colosseum - Foreign KCM
Strategy
Fighting Spirit mining rates What's the deal with APM & what's its true value Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Starcraft Tabletop Miniature Game General RTS Discussion Thread Darkest Dungeon
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
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
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1922 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
Hyrule19200 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
Hyrule19200 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
Germany2594 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
Germany2594 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
WardiTV Team League
12:45
Group B
WardiTV532
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 213
SortOf 143
ProTech121
StarCraft: Brood War
Calm 7204
Bisu 3185
Sea 2543
Horang2 1830
Shuttle 946
EffOrt 944
Hyuk 831
Mini 665
Soma 570
Stork 508
[ Show more ]
firebathero 444
actioN 358
ggaemo 296
Rush 293
Snow 268
Soulkey 188
PianO 146
hero 139
sorry 82
Barracks 59
Sea.KH 59
Hyun 55
[sc1f]eonzerg 55
Backho 49
Aegong 37
zelot 33
Shinee 28
Movie 23
Hm[arnc] 22
910 22
Terrorterran 18
scan(afreeca) 14
Rock 12
IntoTheRainbow 12
ajuk12(nOOB) 12
soO 8
Dota 2
Gorgc6336
BananaSlamJamma602
canceldota113
Counter-Strike
x6flipin446
edward92
oskar48
Heroes of the Storm
XaKoH 146
Other Games
singsing1879
B2W.Neo1270
hiko526
crisheroes286
DeMusliM260
KnowMe114
RotterdaM111
ArmadaUGS92
Livibee54
QueenE49
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• iHatsuTV 7
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis2506
• Jankos2093
• TFBlade1133
Upcoming Events
OSC
10h 8m
RSL Revival
20h 8m
TriGGeR vs Cure
ByuN vs Rogue
Replay Cast
1d 10h
RSL Revival
1d 20h
Maru vs MaxPax
BSL
2 days
RSL Revival
2 days
uThermal 2v2 Circuit
3 days
BSL
3 days
Afreeca Starleague
3 days
Replay Cast
4 days
[ Show More ]
Sparkling Tuna Cup
4 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-03-31
WardiTV Winter 2026
NationLESS Cup

Ongoing

BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
CSL Season 20: Qualifier 2
RSL Revival: Season 4
Nations Cup 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

Escore Tournament S2: W1
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
StarCraft2 Community Team League 2026 Spring
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 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.