• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 15:43
CEST 21:43
KST 04:43
  • 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
[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy19ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book20
Community News
$5,000 WardiTV TLMC tournament - Presented by Monster Energy3GSL CK: More events planned pending crowdfunding6Weekly Cups (May 30-Apr 5): herO, Clem, SHIN win0[BSL22] RO32 Group Stage5Weekly Cups (March 23-29): herO takes triple6
StarCraft 2
General
comprar pods para vapeo Team Liquid Map Contest #22 - Presented by Monster Energy Quebec Clan still alive ? BGE Stara Zagora 2026 cancelled Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool
Tourneys
$5,000 WardiTV TLMC tournament - Presented by Monster Energy GSL CK: More events planned pending crowdfunding Sea Duckling Open (Global, Bronze-Diamond) Sparkling Tuna Cup - Weekly Open Tournament RSL Season 4 announced for March-April
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
The PondCast: SC2 News & Results Mutation # 520 Moving Fees Mutation # 519 Inner Power Mutation # 518 Radiation Zone
Brood War
General
ASL21 General Discussion [BSL22] RO32 Group Stage BW General Discussion so ive been playing broodwar for a week straight. Gypsy to Korea
Tourneys
Escore Tournament StarCraft Season 2 [Megathread] Daily Proleagues [ASL21] Ro24 Group F [BSL22] RO32 Group B - Sunday 21:00 CEST
Strategy
Fighting Spirit mining rates Muta micro map competition What's the deal with APM & what's its true value Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Starcraft Tabletop Miniature Game Nintendo Switch Thread Darkest Dungeon
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
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 The China Politics Thread European Politico-economics QA Mega-thread Trading/Investing Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
How Streamers Inspire Gamers…
TrAiDoS
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
ASL S21 English Commentary…
namkraft
StarCraft improvement
iopq
Electronics
mantequilla
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2732 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
Spain18258 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
Poland17719 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
Hyrule19202 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
BSL
19:00
RO32 Group A
n0maD vs perroflaco
TerrOr vs ZZZero
MadiNho vs WolFix
DragOn vs LancerX
ZZZero.O165
LiquipediaDiscussion
PSISTORM Gaming Misc
15:55
FSL s10 code A/B Championships
Freeedom35
Liquipedia
uThermal 2v2 Circuit
15:00
Season 2 - Bonus Cup 7
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
BRAT_OK 96
Ketroc 62
PattyMac 55
CosmosSc2 2
StarCraft: Brood War
Britney 16618
Mini 505
Shuttle 403
firebathero 190
ZZZero.O 165
Dewaltoss 136
Soulkey 75
ggaemo 50
Rock 43
Sexy 37
[ Show more ]
910 26
NaDa 9
Dota 2
monkeys_forever433
ROOTCatZ5
Counter-Strike
pashabiceps2325
Heroes of the Storm
Liquid`Hasu284
Khaldor237
MindelVK9
Other Games
summit1g6439
Grubby3147
FrodaN2046
B2W.Neo807
crisheroes232
QueenE69
Trikslyr65
Organizations
Other Games
gamesdonequick740
StarCraft 2
CranKy Ducklings88
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• printf 71
• Adnapsc2 17
• CranKy Ducklings SOOP9
• OhrlRock 4
• sooper7s
• Migwel
• LaughNgamezSOOP
• IndyKCrew
• Kozan
• intothetv
• AfreecaTV YouTube
StarCraft: Brood War
• 3DClanTV 16
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV1437
League of Legends
• TFBlade2400
Other Games
• imaqtpie1251
• Shiphtur252
• tFFMrPink 15
Upcoming Events
Sparkling Tuna Cup
14h 17m
WardiTV Team League
15h 17m
OSC
17h 17m
BSL
23h 17m
Sterling vs Azhi_Dahaki
Napoleon vs Mazur
Jimin vs Nesh
spx vs Strudel
IPSL
23h 17m
Artosis vs TBD
Napoleon vs TBD
Replay Cast
1d 13h
Wardi Open
1d 14h
Afreeca Starleague
1d 14h
Soma vs YSC
Sharp vs sSak
Monday Night Weeklies
1d 20h
Afreeca Starleague
2 days
Snow vs PianO
hero vs Rain
[ Show More ]
GSL
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
The PondCast
4 days
Escore
5 days
Korean StarCraft League
6 days
CranKy Ducklings
6 days
IPSL
6 days
WolFix vs nOmaD
dxtr13 vs Razz
BSL
6 days
Liquipedia Results

Completed

Escore Tournament S2: W2
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
StarCraft2 Community Team League 2026 Spring
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W3
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
RSL Revival: Season 5
WardiTV TLMC #16
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 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.