• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 20:54
CET 02:54
KST 10:54
  • 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
Behind the Blue - Team Liquid History Book15Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8herO wins SC2 All-Star Invitational14
Community News
ACS replaced by "ASL Season Open" - Starts 21/0222LiuLi Cup: 2025 Grand Finals (Feb 10-16)37Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2Nexon's StarCraft game could be FPS, led by UMS maker11PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)15
StarCraft 2
General
Nexon's StarCraft game could be FPS, led by UMS maker How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Terran Scanner Sweep Behind the Blue - Team Liquid History Book Weekly Cups (Jan 12-18): herO, MaxPax, Solar win
Tourneys
LiuLi Cup: 2025 Grand Finals (Feb 10-16) SC2 AI Tournament 2026 PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) Sparkling Tuna Cup - Weekly Open Tournament RSL Season 4 announced for March-April
Strategy
Custom Maps
Map Editor closed ? [A] Starcraft Sound Mod
External Content
Mutation # 513 Attrition Warfare The PondCast: SC2 News & Results Mutation # 512 Overclocked Mutation # 511 Temple of Rebirth
Brood War
General
TvZ is the most complete match up Which units you wish saw more use in the game? Ladder maps - how we can make blizz update them? ACS replaced by "ASL Season Open" - Starts 21/02 StarCraft player reflex TE scores
Tourneys
[Megathread] Daily Proleagues Escore Tournament StarCraft Season 1 Small VOD Thread 2.0 KCM Race Survival 2026 Season 1
Strategy
Fighting Spirit mining rates Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta
Other Games
General Games
Diablo 2 thread Path of Exile ZeroSpace Megathread Nintendo Switch Thread Battle Aces/David Kim RTS Megathread
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 Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Ask and answer stupid questions here! Things Aren’t Peaceful in Palestine European Politico-economics QA Mega-thread
Fan Clubs
The IdrA Fan Club The herO Fan Club!
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
The Search For Meaning in Vi…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2415 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
Spain18216 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
Poland17662 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
Hyrule19192 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
Replay Cast
00:00
HomeStory Cup 28 - Group C
CranKy Ducklings120
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 155
Ketroc 67
Dota 2
syndereN894
NeuroSwarm37
Counter-Strike
fl0m2035
Fnx 1372
taco 579
Super Smash Bros
C9.Mang0750
hungrybox529
Mew2King87
Heroes of the Storm
Khaldor183
Other Games
gofns21650
tarik_tv15549
Artosis936
JimRising 767
Maynarde100
ViBE52
Organizations
Other Games
gamesdonequick1375
BasetradeTV105
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• Hupsaiya 104
• davetesta44
• mYiSmile114
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• Airneanach20
• Azhi_Dahaki19
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Doublelift4714
• Scarra1686
Other Games
• imaqtpie1800
Upcoming Events
Replay Cast
7h 6m
Wardi Open
10h 6m
Monday Night Weeklies
15h 6m
OSC
22h 6m
WardiTV Winter Champion…
1d 10h
PiGosaur Cup
1d 23h
Replay Cast
2 days
WardiTV Winter Champion…
2 days
Replay Cast
2 days
PiG Sty Festival
3 days
[ Show More ]
The PondCast
3 days
KCM Race Survival
3 days
WardiTV Winter Champion…
3 days
Replay Cast
3 days
PiG Sty Festival
4 days
Epic.LAN
4 days
Replay Cast
4 days
PiG Sty Festival
5 days
CranKy Ducklings
5 days
Epic.LAN
5 days
Replay Cast
5 days
PiG Sty Festival
6 days
Sparkling Tuna Cup
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-02-14
LiuLi Cup: 2025 Grand Finals
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Nations Cup 2026
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025

Upcoming

Escore Tournament S1: King of Kings
[S:21] ASL SEASON OPEN 1st Round
[S:21] ASL SEASON OPEN 1st Round Qualifier
[S:21] ASL SEASON OPEN 2nd Round
[S:21] ASL SEASON OPEN 2nd Round Qualifier
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
WardiTV Winter 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
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.