• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 01:08
CEST 07:08
KST 14:08
  • 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?8Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris45Weekly 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? #1: Maru - Greatest Players of All Time Maestros of the Game: Week 1/Play-in Preview Weekly Cups (Aug 11-17): MaxPax triples again! 2024/25 Off-Season Roster Moves
Tourneys
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 $5,100+ SEL Season 2 Championship (SC: Evo)
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
ASL20 General Discussion No Rain in ASL20? Victoria gamers Starcraft at lower levels TvP BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Is there English video for group selection for ASL [ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Warcraft III: The Frozen Throne
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 Canadian Politics Mega-thread Russo-Ukrainian War 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
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: 1571 users

The Big Programming Thread - Page 216

Forum Index > General Forum
Post a Reply
Prev 1 214 215 216 217 218 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.
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
Hyrule19083 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
Hyrule19083 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
Germany2577 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
Germany2577 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 4h 52m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft563
ProTech89
NeuroSwarm 84
StarCraft: Brood War
Shuttle 831
sSak 256
Hyuk 238
Snow 135
HiyA 73
Aegong 57
Noble 46
NaDa 21
Icarus 5
Counter-Strike
Stewie2K567
Super Smash Bros
hungrybox278
Other Games
shahzam942
JimRising 508
C9.Mang0456
Maynarde115
Mew2King47
RuFF_SC243
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• practicex 29
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Diggity5
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1501
• Lourlo1011
• Stunt580
Other Games
• Scarra954
Upcoming Events
Sparkling Tuna Cup
4h 52m
PiGosaur Monday
18h 52m
LiuLi Cup
1d 5h
Replay Cast
1d 18h
The PondCast
2 days
RSL Revival
2 days
Maru vs SHIN
MaNa vs MaxPax
OSC
2 days
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
3 days
Reynor vs Astrea
Classic vs sOs
BSL Team Wars
3 days
Team Bonyth vs Team Dewalt
CranKy Ducklings
4 days
[ Show More ]
RSL Revival
4 days
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
4 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
[BSL 2025] Weekly
4 days
RSL Revival
5 days
Cure vs Bunny
Creator vs Zoun
BSL Team Wars
5 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
6 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
Thunderpick World Champ.
MESA Nomadic Masters Fall
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.