• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:52
CET 14: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
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
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
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1421 users

The Big Programming Thread - Page 842

Forum Index > General Forum
Post a Reply
Prev 1 840 841 842 843 844 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.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2017-02-12 00:59:18
February 12 2017 00:58 GMT
#16821
Or, if you decide to do C++, you can do this instead:

constexpr size_t ARRAY_LENGTH = 50;
T arr[ARRAY_LENGTH];

C would be just outdated if it wasn't for embedded systems, operating systems and drivers.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 12 2017 01:18 GMT
#16822
In C, can I refer to an array index by the value of another array?

like


int array[5];
int array_two[5];

array_two[3] = 1;

array[array_two[3]] = 7;
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
February 12 2017 01:45 GMT
#16823
Did compiler stop working for you? Part of fun is to compile and see.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 12 2017 01:47 GMT
#16824
sigh

*goes and checks*
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2017-02-12 01:55:42
February 12 2017 01:51 GMT
#16825
Wow, I've just tried to replace 5 with the following:

const int SIZE = 5;
int array[SIZE];

Fine in C++. Not compiling in C. Fuck you C. :D
That said, if I was going to do it properly in C++, it would be:

constexpr size_t SIZE = 5;

Your example compiles and runs fine in C and C++. However, I'd advise you to stick with size_t instead of int for size of array. size_t is an unsigned integer or unsigned long long, so it doesn't make sense for size of arrays to have a negative value.
Hanh
Profile Joined June 2016
146 Posts
Last Edited: 2017-02-12 03:22:31
February 12 2017 03:17 GMT
#16826
These dynamic arrays are allocated from the stack. Unless you can make sure that they are small you shouldn't spend stack space because it's only typically a few K in size.
If you want to allocate dynamically from the stack, there is the function 'alloca'
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2017-02-13 00:07:13
February 13 2017 00:05 GMT
#16827
On February 12 2017 12:17 Hanh wrote:
These dynamic arrays are allocated from the stack. Unless you can make sure that they are small you shouldn't spend stack space because it's only typically a few K in size.
If you want to allocate dynamically from the stack, there is the function 'alloca'


Good to know if I ever have to write pure C code without malloc. I remember at university there was some task to ask user for numbers. Catch was not knowing how many they are, so we had to do some dumb stuff like

#define ARRAY_LENGTH 1000

And hope it's enough...

Good thing is you have std::vector<type> in such cases, but alas, it was a C module. I suppose you can still do a dynamic array like vector, but you will just have to reinvent the wheel.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-02-13 00:41:51
February 13 2017 00:40 GMT
#16828
--- Nuked ---
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-13 02:46:53
February 13 2017 02:43 GMT
#16829
-lol misread-
There is no one like you in the universe.
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-02-13 03:35:16
February 13 2017 03:09 GMT
#16830
snippet of my code in python:

'solved'

I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT

Anyone know why this is? I'm pretty sure I did this correctly but I guess not

edit:

holy lol

apparently def whatever (x, self) doesn't work? I did not know self had to be the first argument. sigh I hate syntax issues lol
TL/SKT
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-13 03:36:38
February 13 2017 03:34 GMT
#16831
On February 13 2017 12:09 dsyxelic wrote:
snippet of my code in python:


from array import array
class ListArray:

maxlength = 100
elements = array('i')
last = -1

def __init__(self):
self.elements=[0]*self.maxlength

#return position of last index+1
def END(self):
return last+1

def INSERT(x, p, self):
if (self.last+1 >= self.maxlength):
print 'Error: Cannot insert, list is full.'


I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT

Anyone know why this is? I'm pretty sure I did this correctly but I guess not


AFAIK

   def INSERT(x, p, self):


should be

   def INSERT(self, x, p):


otherwise you should be calling x.last
There is no one like you in the universe.
dsyxelic
Profile Joined May 2010
United States1417 Posts
February 13 2017 03:36 GMT
#16832
On February 13 2017 12:34 Blisse wrote:
Show nested quote +
On February 13 2017 12:09 dsyxelic wrote:
snippet of my code in python:


from array import array
class ListArray:

maxlength = 100
elements = array('i')
last = -1

def __init__(self):
self.elements=[0]*self.maxlength

#return position of last index+1
def END(self):
return last+1

def INSERT(x, p, self):
if (self.last+1 >= self.maxlength):
print 'Error: Cannot insert, list is full.'


I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT

Anyone know why this is? I'm pretty sure I did this correctly but I guess not


AFAIK


def INSERT(x, p, self):


should be


def INSERT(self, x, p):


otherwise you should be calling x.last


thank you haha I just realized that.
IDE's are helpful. I tried my code in an IDE and it basically told me what to fix right away. I should use the IDE more when I have syntax problems.
TL/SKT
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-02-13 03:49:43
February 13 2017 03:46 GMT
#16833
--- Nuked ---
dsyxelic
Profile Joined May 2010
United States1417 Posts
February 13 2017 04:03 GMT
#16834
On February 13 2017 12:46 Nesserev wrote:
Show nested quote +
On February 13 2017 12:09 dsyxelic wrote:
snippet of my code in python:

'solved'

I'm getting 'AttributeError: 'int' object has no attribute 'last'' on line the first line of my def INSERT

Anyone know why this is? I'm pretty sure I did this correctly but I guess not

edit:

holy lol

apparently def whatever (x, self) doesn't work? I did not know self had to be the first argument. sigh I hate syntax issues lol

Self has to be the first parameter of your class method, because the object on which the method is called, is always passed as the first argument. (The parameter's name doesn't have to be self though... but you should call it self anyway, because conventions.).

Second, I also noticed that you made maxlength, elements and last class member, so basically every instance of ListArray would share those variables... if you have more than one instance of said class, they'd probably overwrite each other constantly. Instead, instance members should be initialized in the __init__ function, any other class function, or just x.member from the "outside".


class ListArray:

maxlength = 100 # class member, one per class, shared by all instances

def __init__(self):
self.elements=array('i') # instance member, one per instance
self.last = -1


Basically, instance members have to be tagged on. When you say x = ListArray(), you start out with an "empty" object, and __init__ for ListArray is run, which first adds the elements member, and then the last member.


Thank you, that was really helpful. That was silly of me.
Everything's working great now, thank you!
TL/SKT
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
February 13 2017 11:11 GMT
#16835
https://datamancer.com/

Fuuuuck me! Why do I have to be so poor?
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
February 13 2017 17:02 GMT
#16836
--- Nuked ---
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
February 13 2017 19:07 GMT
#16837
I've been asked if there is any significant technology coming up for computing, but I don't know anything major other than quantum computer. Is there anything else?
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
February 13 2017 21:25 GMT
#16838
On February 14 2017 04:07 Shield wrote:
I've been asked if there is any significant technology coming up for computing, but I don't know anything major other than quantum computer. Is there anything else?


Besides quantum computing you have some closer goals, like everything working under 64bit architecture, parallelism everywhere and all programs being able to utilize all of the cores. But that's more on the software side. In hardware we already have some new materials like graphene, some cooling technologies without the use of fans or water (plates that bend under temperature and generate air flow) etc. etc.

Currently we're pretty much at the limit of silicon and other materials so until something new comes along and is cheap enough to mass-produce we're pretty much done (notice that for some years now CPU clock speed doesn't really increase, just the number of cores does).
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 13 2017 22:26 GMT
#16839
Let's go over some discrete math questions I am unsure about!

give an infinite subset X in Q that contains no elements in set N
my answer: Q less than 0 (this one seemed easy but it's weird so im checking)

give an infinite subset X in R that contains no elements in set Q
my answer: the set of irrational numbers? though I know of no actual proof that this set is infinite in size, I am just guessing it is



find an infinite domain where the statement is true OR show that there is NO such domain. explain. then do the same but attempting to show that the statement is false.

(for all x)(there exists y)[(x < y < 1 ) and (not (x < z < y) ]

for False, I say the natural numbers. If y < 1, then y must be 0. So x cannot be less than y.

for True, we know we our domain must not be a dense set (I've got this right, correct?) since there is no z between x and y. So we are dealing with integers or some such. But there doesn't seem to be any domain that actually works here, because we can't find a y > x and less than 1 in a set that isn't dense.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
February 13 2017 23:03 GMT
#16840
On February 14 2017 07:26 travis wrote:
give an infinite subset X in Q that contains no elements in set N
my answer: Q less than 0 (this one seemed easy but it's weird so im checking)

That works. Also any subset that is each element in N plus some fraction between 0 and 1, or 1 divided by all integer numbers greater than 1 and so on...

On February 14 2017 07:26 travis wrote:
give an infinite subset X in R that contains no elements in set Q
my answer: the set of irrational numbers? though I know of no actual proof that this set is infinite in size, I am just guessing it is

Can get real creative with this one too. Like I'm pretty sure that the set of all n-th roots of 3 where n in N and n > 1 should fit. Integer (except 0) multiples of pi (or any irrational number) work just as well.
If you have a good reason to disagree with the above, please tell me. Thank you.
Prev 1 840 841 842 843 844 1032 Next
Please log in or register to reply.
Live Events Refresh
CranKy Ducklings
10:00
Sea Duckling Open #140
CranKy Ducklings79
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 198
Railgan 42
Creator 14
StarCraft: Brood War
Sea 6694
Horang2 4040
GuemChi 1668
Jaedong 862
actioN 292
Mini 259
BeSt 247
Killer 230
Soma 220
EffOrt 210
[ Show more ]
Rush 169
Mind 92
Hyun 87
Bonyth 72
ToSsGirL 69
Backho 61
sas.Sziky 33
JYJ28
PianO 27
zelot 24
Aegong 14
soO 12
Terrorterran 10
Sacsri 9
sorry 9
HiyA 8
Dota 2
Gorgc6041
singsing2210
qojqva1772
Dendi596
XcaliburYe214
BananaSlamJamma90
Heroes of the Storm
Khaldor209
Other Games
B2W.Neo1194
Lowko261
Sick244
Fuzer 193
Hui .112
XaKoH 95
nookyyy 54
MindelVK19
Organizations
StarCraft 2
WardiTV622
Counter-Strike
PGL242
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 67
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2050
League of Legends
• Stunt703
• HappyZerGling113
Upcoming Events
IPSL
4h 8m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
4h 8m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
6h 8m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
9h 8m
Sparkling Tuna Cup
20h 8m
WardiTV Korean Royale
22h 8m
LAN Event
1d 1h
IPSL
1d 4h
JDConan vs WIZARD
WolFix vs Cross
BSL 21
1d 6h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
1d 19h
[ Show More ]
Wardi Open
1d 22h
WardiTV Korean Royale
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
4 days
RSL Revival
4 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
RSL Revival
5 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
5 days
CranKy Ducklings
6 days
RSL Revival
6 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
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

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals 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.