• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:31
CEST 18:31
KST 01: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
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
BSL Team A vs Koreans - Sat-Sun 16:00 CET6Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)80Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition32
StarCraft 2
General
The New Patch Killed Mech! TL.net Map Contest #21: Voting Revisiting the game after10 years and wow it's bad Stellar Fest: StarCraft II returns to Canada herO Talks: Poor Performance at EWC and more...
Tourneys
SC2's Safe House 2 - October 18 & 19 Sparkling Tuna Cup - Weekly Open Tournament $1,200 WardiTV October (Oct 21st-31st) WardiTV Mondays RSL Offline Finals Dates + Ticket Sales!
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ BW caster Sayle BSL Team A vs Koreans - Sat-Sun 16:00 CET BW General Discussion Question regarding recent ASL Bisu vs Larva game
Tourneys
[ASL20] Semifinal B [Megathread] Daily Proleagues SC4ALL $1,500 Open Bracket LAN [ASL20] Semifinal A
Strategy
Current Meta BW - ajfirecracker Strategy & Training Relatively freeroll strategies Siegecraft - a new perspective
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Path of Exile Nintendo Switch Thread ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Series you have seen recently... Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The Heroism of Pepe the Fro…
Peanutsc
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1512 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
Hyrule19144 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
Hyrule19144 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
Germany2579 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
Germany2579 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
LamboSC2 492
ProTech79
BRAT_OK 56
MindelVK 20
StarCraft: Brood War
Soma 1529
Horang2 1474
Light 830
ZerO 751
Barracks 697
Larva 685
Mini 589
Stork 448
actioN 423
firebathero 312
[ Show more ]
hero 273
Hyun 262
JulyZerg 172
PianO 123
ggaemo 114
Rush 93
sorry 70
Pusan 66
Dewaltoss 63
Mong 62
Sharp 52
zelot 49
ToSsGirL 23
Sacsri 21
Terrorterran 18
scan(afreeca) 11
NaDa 11
ajuk12(nOOB) 8
Dota 2
Gorgc8460
qojqva2660
Fuzer 321
Counter-Strike
olofmeister1983
fl0m1797
Heroes of the Storm
Khaldor607
Liquid`Hasu371
Other Games
singsing2117
B2W.Neo1197
Skadoodle302
Hui .244
ArmadaUGS169
KnowMe160
ZerO(Twitch)34
Trikslyr30
Organizations
Other Games
BasetradeTV26
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• HeavenSC 28
• Adnapsc2 23
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 9
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 3590
• lizZardDota241
League of Legends
• Jankos3420
Upcoming Events
Safe House 2
29m
IPSL
2h 29m
Sziky vs Havi
Artosis vs Klauso
Monday Night Weeklies
23h 29m
WardiTV Invitational
1d 18h
WardiTV Invitational
1d 21h
Tenacious Turtle Tussle
3 days
The PondCast
3 days
WardiTV Invitational
4 days
Online Event
4 days
RSL Revival
5 days
[ Show More ]
RSL Revival
5 days
WardiTV Invitational
5 days
Afreeca Starleague
6 days
Snow vs Soma
Sparkling Tuna Cup
6 days
WardiTV Invitational
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 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.