• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:28
CEST 09:28
KST 16:28
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Weekly Cups (June 30 - July 6): Classic Doubles0[BSL20] Non-Korean Championship 4x BSL + 4x China3Flash Announces Hiatus From ASL63Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event22
StarCraft 2
General
Weekly Cups (June 30 - July 6): Classic Doubles Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form?
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
SC uni coach streams logging into betting site Player “Jedi” cheat on CSL Flash Announces Hiatus From ASL BW General Discussion Practice Partners (Official)
Tourneys
CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China The Casual Games of the Week Thread [BSL20] Grand Finals - Sunday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread What do you want from future RTS games? Beyond All Reason
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Stop Killing Games - European Citizens Initiative US Politics Mega-thread Summer Games Done Quick 2024! Summer Games Done Quick 2025! Russo-Ukrainian War Thread
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 652 users

The Big Programming Thread - Page 856

Forum Index > General Forum
Post a Reply
Prev 1 854 855 856 857 858 1031 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
Spain17971 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
Poland17243 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
Hyrule19031 Posts
March 06 2017 01:38 GMT
#17120
killjoy
Liquipediaasante sana squash banana
Prev 1 854 855 856 857 858 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 32m
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Mong 204
Leta 197
Zeus 169
Mind 90
Shine 30
Sharp 23
yabsab 13
Bale 12
Dota 2
XaKoH 537
Counter-Strike
shoxiejesuss193
Super Smash Bros
Mew2King160
Other Games
Stewie2K495
SortOf106
NeuroSwarm101
ProTech47
Happy30
Pyrionflax26
Organizations
Other Games
gamesdonequick30276
BasetradeTV10
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH376
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2219
League of Legends
• Rush1616
• HappyZerGling147
Upcoming Events
Wardi Open
3h 32m
Replay Cast
16h 32m
Sparkling Tuna Cup
1d 2h
WardiTV European League
1d 8h
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
1d 16h
The PondCast
2 days
WardiTV European League
2 days
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
uThermal 2v2 Circuit
2 days
Replay Cast
2 days
RSL Revival
3 days
ByuN vs SHIN
Clem vs Reynor
[ Show More ]
Replay Cast
3 days
RSL Revival
4 days
Classic vs Cure
FEL
4 days
RSL Revival
5 days
FEL
5 days
FEL
5 days
Sparkling Tuna Cup
6 days
RSL Revival
6 days
FEL
6 days
Liquipedia Results

Completed

BSL Season 20
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
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
IEM Cologne 2025
FISSURE Playground #1
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.