• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:00
CET 22:00
KST 06:00
  • 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: Winners2Intel 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!20$5,000+ WardiTV 2025 Championship5[BSL21] RO32 Group Stage3Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
TL.net Map Contest #21: Winners Starcraft, SC2, HoTS, WC3, returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond) $3,500 WardiTV Korean Royale S4
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
BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review [BSL21] RO32 Group Stage Practice Partners (Official) [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION
Strategy
Current Meta How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV ZeroSpace Megathread General RTS Discussion Thread
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
Anime Discussion Thread Movie Discussion! [Manga] One Piece 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
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Career Paths and Skills for …
TrAiDoS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1245 users

The Big Programming Thread - Page 899

Forum Index > General Forum
Post a Reply
Prev 1 897 898 899 900 901 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.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-07-20 07:37:32
July 20 2017 07:37 GMT
#17961
On July 19 2017 10:02 dsyxelic wrote:
can anyone help a c noob?
--
say there is a text file with a string, say "abcdefghijk"

read in that file and delete a substring from it (have file update the new string)
--
is there a very simple way to do this?

so far all I got is fopen with the r+ mode and fgetc which doesn't seem to be what i'm looking for..

any easy to read resource or pointers(heh) for the best approach would be greatly appreciated. I've only gotten around to parsing individual strings from file or going by each character, but not substrings :/


The easiest way is: read the entire file into a string, delete the substring you want, and replace the file with the new string.
There is no one like you in the universe.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
July 21 2017 09:22 GMT
#17962
--- Nuked ---
Six.Strings
Profile Joined July 2017
48 Posts
July 31 2017 10:47 GMT
#17963
Not exactly programming but webdev:

I have a personal website for my CV etc. I made with HTML5, CSS and JS.

Now I want to apply internationally and I'm trying to figure out how to more elegantly switch languages on my site.
Thus far, I just copied the entire HTML file and replaced the German text with the English one, and the CSS and JS files linked to either one. Is there a more elegant solution to this?
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2017-07-31 12:13:20
July 31 2017 12:10 GMT
#17964
On July 31 2017 19:47 Six.Strings wrote:
Not exactly programming but webdev:

I have a personal website for my CV etc. I made with HTML5, CSS and JS.

Now I want to apply internationally and I'm trying to figure out how to more elegantly switch languages on my site.
Thus far, I just copied the entire HTML file and replaced the German text with the English one, and the CSS and JS files linked to either one. Is there a more elegant solution to this?


Are you using any backend? Any framework at all? Those usually come with such features built-in.

If you want to build it from scratch, then just load translations with JS.

1. Create button(s) to select language, all they should really do is just change a variable/cookie or whatever else where your store your language setting.
2. Create your translation files. YAML is amazing for this.
3. Create translation function using. Usually, this looks something like this:

var text = translate('some.property');

4. Use this function instead of regular text in your views.

Sample:


# locales/en.yml
messages:
welcome: 'Welcome!'

# locales/de.yml
messages:
welcome: 'Wilkommen!'

# my.js
const yaml = require('js-yaml');
const fs = require('fs');

try {
const translations = yaml.safeLoad(fs.readFileSync(locale + '.yml', 'utf8'));
} catch (e) {
console.error(e);
}

function translate(key) {
return getMessageByKey(translations, key);
}

function getMessageByKey(obj, key) {
if (!key) {
return obj;
}

var prop, props = key.split('.');

for (var i = 0, len = props.length - 1; i < len; i++) {
prop = props[i];

var candidate = obj[prop];

if (candidate !== undefined) {
obj = candidate;
} else {
break;
}
}

return obj[props[i]];
}


Or, you could just use this: http://www.openxrest.com/translatejs/
Time is precious. Waste it wisely.
dsyxelic
Profile Joined May 2010
United States1417 Posts
Last Edited: 2017-08-03 22:01:01
August 03 2017 19:28 GMT
#17965

# ********
# * *
# * **** *
# * * * *
# * * * *
# * * ** *
# * * *
# * ******
# 8x8 example

def spiral(rows, cols):
#print out a spiral similar to the one above given rows and cols
#can be a rectangle too


so this is a question I found off a mock interview and I've been stuck on it. Any ideas?


Also sorry for the ugly spiral up there, tried to format it so that it looks normal but eh.. looked fine on notepad and my ide so must be something with the spacing here

Edit: ok the spiral got destroyed lol, if it ppl dont get what it should look like ill upload a pic when i get home.

Basically must have empty spaces around it besides the box it came from and is going to
TL/SKT
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
August 03 2017 19:58 GMT
#17966

# ********
# * *
# * **** *
# * * * *
# * * * *
# * * ** *
# * * *
# * ******


Something like this?
There is no one like you in the universe.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
August 03 2017 20:55 GMT
#17967
Use the
[code]
tag to get that kind of formatting.
If you have a good reason to disagree with the above, please tell me. Thank you.
dsyxelic
Profile Joined May 2010
United States1417 Posts
August 03 2017 21:58 GMT
#17968
On August 04 2017 04:58 Blisse wrote:

# ********
# * *
# * **** *
# * * * *
# * * * *
# * * ** *
# * * *
# * ******


Something like this?


yes exactly
TL/SKT
Deckard.666
Profile Joined September 2012
152 Posts
Last Edited: 2017-08-03 23:26:34
August 03 2017 23:23 GMT
#17969
Kinda ugly, but it works.


def spiral(rows, cols):
matrix = [[' ' for _ in range(cols)] for _ in range(rows)]
dimensions = [rows, cols]
pos = [rows - 1, 0]
direction = [-1, 0]
k = 0
i = 0
while True:
t = 0
while (pos[i % 2] >= k or i in [1, 2]) and \
(pos[i % 2] < dimensions[i % 2] - k or i in [0, 3]):
t += 1
matrix[pos[0]][pos[1]] = "*"
pos[0] += direction[0]
pos[1] += direction[1]
if t <= 2:
break
pos[0] -= direction[0]
pos[1] -= direction[1]
direction = [direction[1], -direction[0]]
i = (i + 1) % 4
if i == 3:
k += 2
for row in matrix:
print(''.join(row))


edit: didnt work. Now it does :D
dsyxelic
Profile Joined May 2010
United States1417 Posts
August 04 2017 02:47 GMT
#17970
oh wow nice

besides an infinite loop in some test cases its generally pretty working

i have a hard time understanding your solution though, how does it work?
TL/SKT
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-08-04 06:53:30
August 04 2017 06:42 GMT
#17971
--- Nuked ---
Deckard.666
Profile Joined September 2012
152 Posts
August 04 2017 16:50 GMT
#17972
On August 04 2017 11:47 dsyxelic wrote:
oh wow nice

besides an infinite loop in some test cases its generally pretty working

i have a hard time understanding your solution though, how does it work?


Damn, on what test cases does it get stuck?

Anyway, it simply starts in the bottom left corner, with direction up, and starts replacing cells with a '*' and advancing until its k cells away from the border, at which points it turns clockwise. In the first loop k=0, and in every loop of the spiral k increases by 2. When a side of the spiral has a length shorter than 2, it stops (as turning and printing would mess up the spiral).
Acrofales
Profile Joined August 2010
Spain18108 Posts
August 04 2017 18:14 GMT
#17973
How about:

def spiral(x, y):
if x <= 0 or y <= 0:
return
myspiral = [[0 for i in range(0, y)] for j in range(0, x)]
draw_outer(x, y, myspiral)
left_spiral(x - 2, y - 2, myspiral, x - 1, y - 1)
print_spiral(myspiral);

def left_spiral(x, y, myspiral, posx, posy):
if x <= 0:
return
posx = draw_left(x, myspiral, posx, posy)
if y <= 0:
return
posy = draw_up(y, myspiral, posx, posy)

right_spiral(x - 2, y - 2, myspiral, posx, posy)

def right_spiral(x, y, myspiral, posx, posy):
if x <= 0:
return
posx = draw_right(x, myspiral, posx, posy)
if y <= 0:
return
posy = draw_down(y, myspiral, posx, posy)
left_spiral(x - 2, y - 2, myspiral, posx, posy)

def draw_outer(x, y, myspiral):
posy = draw_up(y, myspiral, 0, y-1)
posx = draw_right(x, myspiral, 0, posy)
draw_down(y, myspiral, posx, posy)

def draw_down(y, myspiral, posx, posy):
for i in range(0, y):
myspiral[posx][posy + i] = 1;
return posy + y - 1;

def draw_up(y, myspiral, posx, posy):
for i in range(0, y):
myspiral[posx][posy - i] = 1;
return posy - y + 1;

def draw_right(x, myspiral, posx, posy):
for i in range(0, x):
myspiral[posx + i][posy] = 1;
return posx + x - 1;

def draw_left(x, myspiral, posx, posy):
for i in range(0, x):
myspiral[posx - i][posy] = 1;
return posx - x + 1;

def print_spiral(myspiral):
transposed = list(map(list, zip(*myspiral)))
for row in transposed:
rowstr = ""
for cell in row:
if cell > 0:
rowstr += "X"
else:
rowstr += " "
print rowstr


It's a bit verbose and would be a lot neater by making it object oriented, but I couldn't be bothered. I wasn't sure what the last little bit should look like, so left the guards at <= 0. Can be changed to <= 1 if a 2x2 square is never a desired outcome.
dsyxelic
Profile Joined May 2010
United States1417 Posts
August 04 2017 18:45 GMT
#17974
On August 05 2017 01:50 Deckard.666 wrote:
Show nested quote +
On August 04 2017 11:47 dsyxelic wrote:
oh wow nice

besides an infinite loop in some test cases its generally pretty working

i have a hard time understanding your solution though, how does it work?


Damn, on what test cases does it get stuck?

Anyway, it simply starts in the bottom left corner, with direction up, and starts replacing cells with a '*' and advancing until its k cells away from the border, at which points it turns clockwise. In the first loop k=0, and in every loop of the spiral k increases by 2. When a side of the spiral has a length shorter than 2, it stops (as turning and printing would mess up the spiral).


Nvm haha it was my ide bugging out, my bad.

Ah I see that makes sense. For reference this was asked in a mock for a new grad. The guy couldn't get it tho and the interviewer didnt give the solution so was wondering how to do it.
TL/SKT
mahrgell
Profile Blog Joined December 2009
Germany3943 Posts
August 08 2017 15:36 GMT
#17975
Terminology question:
I have some Distributed Matrix class, and I'm looking for good terms to describe all the "extra/background data" and the "core data".
core data = all the (distributed) Matrix entries, so basically the Matrix itself
extra/background data = all the data how the data is distributed, which threads contains what etc, some central quick access information (like matrix size etc)

I'm kinda sure there is some common terminology for this, but I simply can't find it .

PS: The real class is actually containing more than just a distributed Matrix, but is actually a collection of a few vectors Matrices etc, which for computational reasons are distributed in some special way, so "Matrix data" doesn't really work for "core data"



dekibeki
Profile Joined June 2011
Australia34 Posts
August 08 2017 17:06 GMT
#17976
On August 09 2017 00:36 mahrgell wrote:
Terminology question:
I have some Distributed Matrix class, and I'm looking for good terms to describe all the "extra/background data" and the "core data".
core data = all the (distributed) Matrix entries, so basically the Matrix itself
extra/background data = all the data how the data is distributed, which threads contains what etc, some central quick access information (like matrix size etc)

I'm kinda sure there is some common terminology for this, but I simply can't find it .

PS: The real class is actually containing more than just a distributed Matrix, but is actually a collection of a few vectors Matrices etc, which for computational reasons are distributed in some special way, so "Matrix data" doesn't really work for "core data"



Usually data about data is called metadata. So you're matrix information is your data, and the information saying where certain parts of the matrix are located would be metadata.
mahrgell
Profile Blog Joined December 2009
Germany3943 Posts
August 08 2017 17:16 GMT
#17977
On August 09 2017 02:06 dekibeki wrote:
Show nested quote +
On August 09 2017 00:36 mahrgell wrote:
Terminology question:
I have some Distributed Matrix class, and I'm looking for good terms to describe all the "extra/background data" and the "core data".
core data = all the (distributed) Matrix entries, so basically the Matrix itself
extra/background data = all the data how the data is distributed, which threads contains what etc, some central quick access information (like matrix size etc)

I'm kinda sure there is some common terminology for this, but I simply can't find it .

PS: The real class is actually containing more than just a distributed Matrix, but is actually a collection of a few vectors Matrices etc, which for computational reasons are distributed in some special way, so "Matrix data" doesn't really work for "core data"



Usually data about data is called metadata. So you're matrix information is your data, and the information saying where certain parts of the matrix are located would be metadata.


Thanks... that was exactly what I was looking for. Perfect.
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2017-08-08 23:05:32
August 08 2017 23:04 GMT
#17978
If you were to pick an answer to this question at random, what would be the chance of picking the right one?
a) 25%
b) 50%
c) 60%
d) 25%

Edit: Damn, I forgot we have the math thread now...
Time is precious. Waste it wisely.
Acrofales
Profile Joined August 2010
Spain18108 Posts
August 08 2017 23:06 GMT
#17979
On August 09 2017 08:04 Manit0u wrote:
If you were to pick an answer to this question at random, what would be the chance of picking the right one?
a) 25%
b) 50%
c) 60%
d) 25%

Edit: Damn, I forgot we have the math thread now...

Aren't you a funny guy...
Zocat
Profile Joined April 2010
Germany2229 Posts
August 09 2017 19:21 GMT
#17980
On August 09 2017 08:04 Manit0u wrote:
If you were to pick an answer to this question at random, what would be the chance of picking the right one?


Ill defined question. Wtf does "right one" mean?
Prev 1 897 898 899 900 901 1032 Next
Please log in or register to reply.
Live Events Refresh
LAN Event
18:00
Day 3: Ursa 2v2, FFA
SteadfastSC393
IndyStarCraft 177
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 499
SteadfastSC 393
White-Ra 211
IndyStarCraft 177
UpATreeSC 142
ProTech125
Railgan 67
ROOTCatZ 43
StarCraft: Brood War
Shuttle 460
Bonyth 69
ivOry 14
Dota 2
Dendi985
Counter-Strike
pashabiceps1182
Foxcn163
Super Smash Bros
Liquid`Ken9
Heroes of the Storm
Liquid`Hasu516
Other Games
Beastyqt728
fl0m665
Mlord452
FrodaN427
shahzam403
KnowMe185
Pyrionflax168
C9.Mang0125
ArmadaUGS115
ToD77
Mew2King74
Trikslyr53
OptimusSC21
Organizations
Counter-Strike
PGL192
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• Adnapsc2 11
• Reevou 9
• Dystopia_ 0
• Kozan
• sooper7s
• AfreecaTV YouTube
• Migwel
• LaughNgamezSOOP
• intothetv
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3055
• Ler92
League of Legends
• TFBlade886
Other Games
• imaqtpie1303
• WagamamaTV341
• Scarra290
• Shiphtur221
Upcoming Events
OSC
1h
Replay Cast
2h
OSC
15h
LAN Event
18h
Korean StarCraft League
1d 6h
CranKy Ducklings
1d 13h
LAN Event
1d 18h
IPSL
1d 21h
dxtr13 vs OldBoy
Napoleon vs Doodle
BSL 21
1d 23h
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
2 days
[ Show More ]
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
2 days
LAN Event
2 days
IPSL
2 days
JDConan vs WIZARD
WolFix vs Cross
BSL 21
2 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
3 days
Wardi Open
3 days
WardiTV Korean Royale
4 days
Replay Cast
5 days
Kung Fu Cup
5 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
6 days
The PondCast
6 days
RSL Revival
6 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
6 days
WardiTV Korean Royale
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
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
Esports World Cup 2025

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
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.