• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:09
CEST 06:09
KST 13:09
  • 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
Code S Season 1 (2026) - RO4 & Finals Preview4[ASL21] Ro4 Preview: On Course12Code S Season 1 - RO8 Preview7[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13
Community News
Code S Season 1 (2026) - RO8 Results2Weekly Cups (May 4-10): Clem, MaxPax, herO win1Maestros of The Game 2 announcement and schedule !11Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event12
StarCraft 2
General
Team Liquid Map Contest #22 - The Finalists Code S Season 1 (2026) - RO4 & Finals Preview Code S Season 1 (2026) - RO8 Results Code S Season 1 (2026) - RO12 Results MaNa leaves Team Liquid
Tourneys
GSL Code S Season 1 (2026) Sparkling Tuna Cup - Weekly Open Tournament KSL Week 89 2026 GSL Season 2 Qualifiers Maestros of The Game 2 announcement and schedule !
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
The PondCast: SC2 News & Results Mutation # 526 Rubber and Glue Mutation # 525 Wheel of Misfortune Mutation # 524 Death and Taxes
Brood War
General
vespene.gg — BW replays in browser Data needed BGH Auto Balance -> http://bghmmr.eu/ Pros React to: TvT Masterclass in FlaSh vs Light BW General Discussion
Tourneys
[ASL21] Semifinals B [BSL22] RO8 Bracket Stage + Another TieBreaker [ASL21] Ro8 Day 4 Escore Tournament StarCraft Season 2
Strategy
Muta micro map competition Fighting Spirit mining rates [G] Hydra ZvZ: An Introduction Simple Questions, Simple Answers
Other Games
General Games
Warcraft III: The Frozen Throne Nintendo Switch Thread Path of Exile Stormgate/Frost Giant Megathread Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming
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 TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread European Politico-economics QA Mega-thread YouTube Thread Russo-Ukrainian War Thread UK Politics Mega-thread
Fan Clubs
The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
Travel Agencies vs Online Booking Platforms The Automated Ban List
Blogs
Why RTS gamers make better f…
gosubay
How EEG Data Can Predict Gam…
TrAiDoS
ramps on octagon
StaticNine
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1670 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
Hyrule19213 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
Hyrule19213 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
OSC
00:00
OSC Elite Rising Star #19
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft500
ROOTCatZ 214
RuFF_SC2 211
NeuroSwarm 177
StarCraft: Brood War
GuemChi 6615
HiyA 40
Noble 21
Bale 20
Icarus 5
League of Legends
JimRising 811
Counter-Strike
taco 1093
Other Games
summit1g16654
monkeys_forever361
Maynarde129
Organizations
Other Games
gamesdonequick953
BasetradeTV171
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 13 non-featured ]
StarCraft 2
• Hupsaiya 89
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki23
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1340
Upcoming Events
Replay Cast
4h 51m
Wardi Open
7h 51m
Monday Night Weeklies
11h 51m
Replay Cast
19h 51m
The PondCast
1d 5h
Kung Fu Cup
1d 6h
GSL
2 days
Replay Cast
2 days
GSL
3 days
WardiTV Spring Champion…
3 days
[ Show More ]
Replay Cast
3 days
Sparkling Tuna Cup
4 days
WardiTV Spring Champion…
4 days
Replay Cast
4 days
RSL Revival
5 days
Classic vs SHIN
Rogue vs Bunny
BSL
5 days
Replay Cast
5 days
Afreeca Starleague
6 days
Flash vs Soma
RSL Revival
6 days
BSL
6 days
Patches Events
6 days
Liquipedia Results

Completed

Escore Tournament S2: W7
2026 GSL S1
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
YSL S3
SCTL 2026 Spring
RSL Revival: Season 5
Heroes Pulsing #1
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2

Upcoming

Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
WardiTV Spring 2026
2026 GSL S2
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 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.