• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:51
CEST 12:51
KST 19:51
  • 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 2 (2026) - RO8 Preview4[ASL21] Finals Preview: Two Legacies21Code S Season 2 (2026) - RO12 Preview2herO wins GSL Code S Season 1 (2026)6Code S Season 1 (2026) - RO4 & Finals Preview5
Community News
Weekly Cups (May 18-25): MaxPax wins doubles0Crank Gathers Season 4: BW vs SC2 Team League4Weekly Cups (May 11-17): Classic wins double0Code S Season 1 (2026) - RO8 Results2Weekly Cups (May 4-10): Clem, MaxPax, herO win1
StarCraft 2
General
herO wins GSL Code S Season 1 (2026) Code S Season 2 (2026) - RO8 Preview Weekly Cups (May 18-25): MaxPax wins doubles Code S Season 2 (2026) - RO12 Preview Weekly Cups (May 11-17): Classic wins double
Tourneys
GSL Code S Season 2 (2026) Sparkling Tuna Cup - Weekly Open Tournament Crank Gathers Season 4: BW vs SC2 Team League GSL Code S Season 1 (2026) 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
Mutation # 527 Hell Train The PondCast: SC2 News & Results Mutation # 526 Rubber and Glue Mutation # 525 Wheel of Misfortune
Brood War
General
Every Matchup's Top 5 Winrates (all ASLs & KSLs) Pros React To: ASL S21 Finals BW General Discussion Very long shot - StarCraft x A7X video Pros React to: TvT Masterclass in FlaSh vs Light
Tourneys
Escore Tournament StarCraft Season 2 [BSL22] WB Final & LB Semis - Saturday 21:00 CEST [ASL21] Grand Finals [Megathread] Daily Proleagues
Strategy
Any training maps people recommend? Muta micro map competition [G] Hydra ZvZ: An Introduction Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread ZeroSpace Megathread Path of Exile Stormgate/Frost Giant Megathread 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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Trading/Investing Thread Dating: How's your luck? European Politico-economics QA 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 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
Facing Challenges in Mobile App Development streaming software
TL Community
The Automated Ban List
Blogs
Customization Drives Loyalty…
TrAiDoS
Why RTS gamers make better f…
gosubay
ramps on octagon
StaticNine
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2793 users

The Big Programming Thread - Page 856

Forum Index > General Forum
Post a Reply
Prev 1 854 855 856 857 858 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.
Wrath
Profile Blog Joined July 2014
3174 Posts
March 03 2017 13:55 GMT
#17101
Love the new thread name :D
Acrofales
Profile Joined August 2010
Spain18296 Posts
Last Edited: 2017-03-03 13:59:00
March 03 2017 13:56 GMT
#17102
On March 03 2017 22:36 travis wrote:
hanh or slmw or acrofales or anyone else, could you check over this? (really, I just want one step explained in it. anyone who is good at algebra could explain it)

the problem is to prove this sequence with strong induction

sequence:


a_0 = 12
a_1 = 20
(for all n >= 2)[a_n = 2a_(n-1) + 3a_(n-2)


Show that for all n, a_n <= 12*3^n


so my proof was to first show the base cases.

12 <= 12 * 1
20 <= 12*3

Now make inductive hypothesis.

For some k>= a_1, and for every i: 0 <= i <= k, assume that P(i) holds.
Therefore a_i = 12*3^i

Now do the inductive step by proving P(K+1):


a_(k+1) = 12 * 3^(k+1)

= 2a_k + 3a_(k-1)
= 2(12*3^k)+3(12*3^(k-1))
= 12 * (2*3^k + 3*3^k-1)


and here is where I don't know algebraically what to do next.
I mean obviously, (2*3^k + 3*3^(k-1)) = 3^(k+1)
But what steps are used to prove that?


You need to write your proof in a slightly more rigorous form.

The inductive step works like this:

Assume for any k >=2 that:

a_k <= 12*3^k and a_(k-1), and a_(k-1) <= 12*3^(k-1)

Now prove:

a_(k+1) <= 12*3^(k+1).

Hint: use the fact that 3^k = 3*3^(k - 1)

+ Show Spoiler [not allowed to look until you solve it] +

+ Show Spoiler [really] +

+ Show Spoiler [stop cheating] +

+ Show Spoiler [ok] +


a_(k+1) = 2a_k + 3a_(k-1) From definition
<= 2(12*3^k)+3(12*3^(k-1)) From inductive assumption
= 24*3^k + 12*3^k
= 3^k*(24 + 12)
= 3^k*3*(8+4)
= 3^(k+1)*12

QED




Hanh
Profile Joined June 2016
146 Posts
March 03 2017 13:57 GMT
#17103
+ Show Spoiler +

3*3^(k-1) = 3^k // definition of power
2*3^k + 3^k = (2+1).3^k // factorize 3^k
= 3.3^k = 3^(k+1)

Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
March 03 2017 14:06 GMT
#17104
ah yeah hanh that last step... obvious once i see it lol
acrofales your way was really elegant
thank you guys.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
March 03 2017 21:39 GMT
#17105
ok here is a question
im doing questions in "cracking the coding interview"

it asks: "Given two strings, write a method to decide if one is a permutation of the
other. "

My solution (in java) was to compare their length (make sure they are same length)
then put string one into a hashset.
then check if the hashset contains each character of of string two


Their solution was to sort the strings and see if they are equal. Is my method better?
Zocat
Profile Joined April 2010
Germany2229 Posts
Last Edited: 2017-03-03 22:22:15
March 03 2017 22:18 GMT
#17106
What does "better" mean? There are multiple things you can think about: Speed, memory, readability... are the obvious ones that immediately come to mind. And one version could be better at metric X and worse at metric Y.

Apart from that, I haven't done Java in a long time, but I think your HashSet variant will fail in the case of repeated characters. Example strings "aab" and "abb".
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
March 03 2017 22:23 GMT
#17107
It won't because I have already checked that the strings were the same length. So if there is a repeated character, but the strings have the same length, then it won't be able to find a later character in the string because it will be missing.

By better I am primarily thinking of speed, here. I don't know how they compare in memory, because I don't know how much memory a hashset takes up.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2017-03-04 08:45:29
March 03 2017 22:44 GMT
#17108
On March 04 2017 07:23 travis wrote:
It won't because I have already checked that the strings were the same length. So if there is a repeated character, but the strings have the same length, then it won't be able to find a later character in the string because it will be missing.

By better I am primarily thinking of speed, here. I don't know how they compare in memory, because I don't know how much memory a hashset takes up.

One string can repeat one character, the other another. Same length, no permutation. Look at the example above. Sorting is the best you can do in terms of runtime complexity ( O(n log n) ) unless you assume that your string has only a small number of different possible characters, in which case you can do something similar to a bucket sort ( O(n) ). The hashtable approach mentioned below is faster.
If you have a good reason to disagree with the above, please tell me. Thank you.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
March 03 2017 22:57 GMT
#17109
oh right yeah.. i feel stupid now
sorry zocat
frogmelter
Profile Blog Joined April 2009
United States971 Posts
March 03 2017 23:10 GMT
#17110
You can use a HashMap<Character, Integer> for count and compare the characters in O(N) time.

HashSet doesn't work for the above case as you lose duplicates, but a HashMap to the frequency of the character can do it. Something like this StackOverflow
TL+ Member
Zocat
Profile Joined April 2010
Germany2229 Posts
March 04 2017 03:32 GMT
#17111
On March 04 2017 07:44 spinesheath wrote: Look at the example above.

My initial example was "aa" and "a"; then I realized that he mentioned checking for length, so I changed it. So his response could've been "correct" (regarding my example).

On March 04 2017 07:23 travis wrote:
By better I am primarily thinking of speed, here. I don't know how they compare in memory, because I don't know how much memory a hashset takes up.

You (and me) also don't know what kind of sorting Java uses (thus we have now clue about the mem req). But you need to change your questions and start thinking about that.

Example: I currently have a problem where a kd-tree is fucking efficient and awesome. But I currently need it for 2 lookups. Building the kd-tree is way more complicated and it needs memory to be stored in. The solution is to have a decent solution with a comment "If we need a lot more lookups consider a kd-tree." and let someone else worry about it in the future.
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2017-03-04 03:57:09
March 04 2017 03:56 GMT
#17112
java default sort uses mergesort (like collections.sort), but then it uses timsort for arrays.sort, but then if that arrays.sort is on numbers then it's a quicksort.

or something like that. Been awhile.

frogmelter's histogram approach is probably what you'd expect as a canonical answer to that interview question. But don't sweat it too much.

bucket sort is roughly equivalent to the hashmap solution. In either case you're potentially having like 1million+ keys.
Who after all is today speaking about the destruction of the Armenians?
Manit0u
Profile Blog Joined August 2004
Poland17751 Posts
Last Edited: 2017-03-04 04:00:09
March 04 2017 03:58 GMT
#17113
On March 04 2017 07:23 travis wrote:
It won't because I have already checked that the strings were the same length. So if there is a repeated character, but the strings have the same length, then it won't be able to find a later character in the string because it will be missing.

By better I am primarily thinking of speed, here. I don't know how they compare in memory, because I don't know how much memory a hashset takes up.


It depends on the hash size, architecture, implementation, language etc. (check the link I posted on the previous page - people were discussing hash optimizations in ruby in it - as in, how they're actually implemented in it and various other languages).

And your solution is pretty bad when it comes down to optimization since for each letter in one string you have to check all the letters in the other. The sorting solution is much better since with sorted arrays you simply compare their respective elements.

If you want to practice such interview questions, you can go ahead and tackle another popular one:

Given an input string, return the first non-duplicate letter in it or false if there is none.
Time is precious. Waste it wisely.
Hanh
Profile Joined June 2016
146 Posts
Last Edited: 2017-03-04 15:18:37
March 04 2017 15:18 GMT
#17114
In some cases, for example if you have a lot of strings to check, pre-screening can save you a lot of time.

XOR/sum/multiply (any operation that is fast & commutative) all of your chars together. If the result is different then they can't be permutations.If they are equal, check for real.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
March 04 2017 22:30 GMT
#17115
probably a really easy proof question

essentially In my homework I am being told to "prove" that 69 cannot be written as a sum of multiple of 8 and 11.

Would the correct way to prove this to go through the cases of ( 69 - n(11) ) (mod 8), showing that for each case there is a non zero remainder? Or is there a more elegant way?
meatpudding
Profile Joined March 2011
Australia520 Posts
March 04 2017 23:57 GMT
#17116
On March 05 2017 07:30 travis wrote:
probably a really easy proof question

essentially In my homework I am being told to "prove" that 69 cannot be written as a sum of multiple of 8 and 11.

Would the correct way to prove this to go through the cases of ( 69 - n(11) ) (mod 8), showing that for each case there is a non zero remainder? Or is there a more elegant way?


I guess one way to do it is to note that 69 (mod 8) = 5.
Then by factorising you must have 8a + 11b (mod 8) = 5.
This reduces to 0 + 3b (mod 8) = 5.
So b = 3^(-1) * 5 = 3 * 5 = 7.
Since a is anything and b is 7, then from the original factorisation we have at least 11 * 7 which is 77 > 69. So the factorisation isn't possible.
Be excellent to each other.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
March 05 2017 21:29 GMT
#17117
In angularjs, I have 3 models from HTML elements with ng-model. These elements are sliders. When I leave them like this they start off undefined until you move the slider. I would like to know a way to have them start off as defined(default 0).

I set them in the scope of my controller, but then the values do not get updated when I move the sliders.

How can you make it so that the model can be initialized to the same value as the slider, while also updating based on the slider being moved?
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Thaniri
Profile Blog Joined March 2011
1264 Posts
Last Edited: 2017-03-06 17:06:38
March 05 2017 23:50 GMT
#17118
I'm just learning angular as well, maybe these code snippets might help:

Directive:

myDirectives.directive('myStars', function () {
return {
restrict: 'A',
replace: true,
scope: {
rating: '=',
max: '='
},
link: function ($scope) {
var updateStars = function () {
$scope.stars = [];
for (var i = 0; i < $scope.max; i++) {
if (i < $scope.rating)
$scope.stars.push({ filled: true });
else
$scope.stars.push({ filled: false });
}
};
$scope.toggle = function (index) {
$scope.rating = index + 1;
updateStars();
};
updateStars();
},
templateUrl: function () { return 'views/stars.html' },
}
});


Partial View:

<ul class="rating">
<li ng-repeat="star in stars ">
<span ng-switch on="star.filled">
<div ng-switch-when="true" class="filled">&#9733;</div>
<div ng-switch-default class="rating">&#9733;</div>


</span>
</li>
<p>{{rating}} out of {{max}} stars.</p>
</ul>


If you make an element <div my-stars rating="3" max="5"></div> the dynamically generated text displayed will be 3 out of 5 stars.

Hopefully that helps a little bit, I'm not an expert >>
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
March 06 2017 00:42 GMT
#17119
Can we please rename thread to what it was? It makes TL look amateur this way.
tofucake
Profile Blog Joined October 2009
Hyrule19215 Posts
March 06 2017 01:38 GMT
#17120
killjoy
Liquipediaasante sana squash banana
Prev 1 854 855 856 857 858 1032 Next
Please log in or register to reply.
Live Events Refresh
GSL
09:30
2026 Season 2: Ro8 Group B
Zoun vs RogueLIVE!
Maru vs TBD
SHIN vs TBD
Ryung 438
IntoTheiNu 330
CranKy Ducklings SOOP41
Rex18
GSL EN (SOOP)0
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Ryung 437
Rex 21
StarCraft: Brood War
Calm 5095
Hyuk 585
Jaedong 377
Horang2 300
BeSt 273
Pusan 231
Mini 205
ZerO 201
EffOrt 192
Leta 171
[ Show more ]
Soulkey 125
ToSsGirL 109
Last 103
Rush 93
ggaemo 68
Light 60
scan(afreeca) 54
hero 51
Shinee 48
Aegong 48
Mind 45
JYJ 34
Sharp 32
soO 30
Free 21
Nal_rA 20
JulyZerg 15
Bale 15
Terrorterran 11
zelot 11
910 11
sorry 10
Movie 7
Dota 2
XcaliburYe154
canceldota53
Counter-Strike
olofmeister1866
x6flipin225
allub202
kRYSTAL_67
markeloff14
Other Games
summit1g9010
B2W.Neo614
Mew2King141
Pyrionflax90
Organizations
StarCraft: Brood War
Kim Chul Min (afreeca) 857
Other Games
gamesdonequick550
Counter-Strike
PGL277
StarCraft: Brood War
lovetv 21
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• iHatsuTV 17
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 7
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis1608
• Jankos1136
Upcoming Events
WardiTV Spring Champion…
1h 9m
SKillous vs Strange
Lambo vs Strange
Ryung vs Strange
Lambo vs Ryung
Ryung vs SKillous
Lambo vs SKillous
OSC
8h 9m
Cham vs Percival
ShoWTimE vs Lambo
Krystianer vs sebesdes
Cure vs Babymarine
SKillous vs Arrogfire
Gerald vs MindelVK
goblin vs TBD
Jumy vs HonMonO
Replay Cast
13h 9m
Maestros of the Game
1d 2h
Replay Cast
1d 13h
RSL Revival
1d 20h
Lambo vs SHIN
Solar vs Rogue
herO vs Clem
Maestros of the Game
2 days
IPSL
2 days
ZZZero vs WorsT
Julia vs eOnzErG
BSL
2 days
TerrOr vs Dewalt
Bonyth vs eOnzErG
Replay Cast
2 days
[ Show More ]
RSL Revival
2 days
Maestros of the Game
3 days
OSC
3 days
IPSL
3 days
Dragon vs Artosis
dxtr13 vs Hawk
BSL
3 days
Wardi Open
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
Sparkling Tuna Cup
4 days
WardiTV Spring Champion…
5 days
Maestros of the Game
5 days
The PondCast
5 days
Maestros of the Game
6 days
Replay Cast
6 days
Replay Cast
6 days
Liquipedia Results

Completed

ASL Season 21
2026 GSL S1
Heroes Pulsing #1

Ongoing

2026 KK StarCraft Pro League
BSL Season 22
IPSL Spring 2026
KCM Race Survival 2026 Season 2
KK 2v2 League Season 1
Acropolis #4
CSCL: Masked Kings S4
SCTL 2026 Spring
WardiTV Spring 2026
2026 GSL S2
RSL Revival: Season 5
Stake Ranked Episode 2
CS Asia Championships 2026
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

Upcoming

Escore Tournament S2: King of Kings
YSL S3
BSL 22 Non-Korean Championship
CSLAN 4
Blizzard Classic Cup 2026
Kung Fu Cup 2026 Grand Finals
CranK Gathers Season 4: BW vs SC2 Team League
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
Bounty Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 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.