[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Interesting problem
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /sci/ - Science & Math

Thread replies: 55
Thread images: 4
File: poo.png (70 KB, 500x451) Image search: [Google]
poo.png
70 KB, 500x451
A new language is created that only uses the letters A, B, C, D, and E. A sequence of letters is called a word if it does not include the same letter twice in a row, and it does not include two vowels in a row. How many words are there in this language that are 10 letters long and that begin with a vowel?

How does /sci/ solve this?
>>
>>8058064
by writing all the possible words and counting.
>>
i really hate combinatorics problems
>>
0 . You can't have words 10 letters long with no repeats allowed and only 5 letters...
>>
>>8058105
This
>>
i really hate problems
>>
>>8058105
Proof that /sci/ is retarded and in denial. This problem is from a 6th grade math exam.
>>
Lmao so easy it's 5x4^9
>>
>>8058121
>A sequence of letters is called a word if it does not include the same letter twice in a row, and it does not include two vowels in a row.

lol no
>>
>>8058130
So basically none of the letters repeat. My answer is correct, actually.
>>
>>8058142
no please tell me you are trolling
>>
>>8058130
Spotted the humanities retard.

lrn2formal languages or gb2/lit/
>>
>>8058165
pls accept the fact that the letters can be used over again
>>
>>8058172
> making 10 letter words from only 5 distinct letters
>>
>>8058185
5 reusable letters
>>
>>8058200
Nah it's clearly the other way.

The answer is 0 OP
>>
>>8058064
>>8058064

a=2*3*b
b=2*c+2*3*d
c=2*d+2*3*e
...
i=2*j+2*3
j=5
Evaluate a
Something like that
>>
>>8058064
pull the lever, they die twice as fast so suffer half as much.
>>
Let
v(n) be the number of words that start with a vowel and end with a vowel.
c(n) be the number of words that start with a vowel and end with a consonant.
Then
v(1) = 1
c(1) = 0
v(n+1) = v(n) + 2*c(n)
c(n+1) = 3*v(n) + 2*c(n)

Written as matrix this is

[eqn] \left( \begin{matrix} v(n+1) \\ c(n+1) \end {matrix} \right) = \left( \begin{matrix} 1 & 2 \\ 3 & 2 \end{matrix} \right) \left( \begin{matrix} v(n) \\ c(n) \end {matrix} \right) [/eqn]

So the solution is
[eqn] v(10) + c(10) = \left( \begin{matrix} 1 & 1 \end {matrix} \right) \left( \begin{matrix} 1 & 2 \\ 3 & 2 \end{matrix} \right)^{9} \left( \begin{matrix} v(1) \\ c(1) \end {matrix} \right) [/eqn]
>>
Answer is 36455768

Let:
P_i = {w | w has a length w_i}
R = {w |w has no two vowels in a row, and no two same letters in a row}
Q = {w |w begins with a vowel}
n_i = card (Pi && R && Q)
m_i = card (Pi && R && not Q)

i.e.
n_i is the number of such words of length i beginning with a vowel
m_i is the number of such words of length i beginning with a consonant

n_1 = card {A,E} = 2
m_1 = card {B,C,D} = 3

And:
n_i = 2*m_(i-1) + n_(i-1)
m_i = 5*(m_(i-1) + n_(i-1))

i.e.
m_2 = 25
n_2 = 8
m_3 = 165
n_3 = 58
m_4 = 1115
n_4 = 388
m_5 = 7515
n_5 = 2618
m_6 = 50665
n_6 = 17648
m_7 = 341565
n_7 = 118978
m_8 = 2302715
n_8 = 802108
m_9 = 15524115
n_9 = 5407538
m_10 = 104658265
And our final result: n_10 = 36455768

--
FistiSWAG, École Normale Supérieure du SWAG
>>
>>8058284
>Solution larger than 2*5^9
You can't be serious.
>>
MULTI
TRACK
DRIFTING
>>
>>8058064
But [math]/omega * 2[/math] is still much, much less than uncountably many people. I don't think you can even have uncountably many people on the track when you can clearly, well, count them.
>>
File: 65246426.png (16 KB, 506x905) Image search: [Google]
65246426.png
16 KB, 506x905
I got halfway through the problem before I gave up.
I plotted out the first part of the problem in pic related
(empty circle is the start, red circles are vowels, black circles are consonants)

The first part is simple enough
from the start, you have 2 options, a or e. From each of those nodes, you have 3 options, the 3 consonants, since you cant have two vowels. So it's 2*3 for words of length 2.
From there, those nodes branch out into 4 i.e. any letter other than itself. So for words of length 3, it's 2*3*4

This is where I'm stuck.

The branching degree of the next level varies because there are 12 vowel nodes that expand into 3, and 12 consonant nodes that branch into 4. (12*3)+(12*4) makes for 84 branches total. So if 24 nodes branch of in 84 directions, that gives an average branching factor of 84/24 = 3.5

The ratio of red vowel nodes to black consonant nodes keeps changing. Just by hand counting, I can see the average branching is approx 3.71428

I don't know where to go from here.
I've never dealt with combinations where the branching varies.
>>
>>8058105
>no repeats
>in a row

ABABABCDE
>>
2*(2^3+2^4+2^4+2^4+2^4+2^4 + 2^4 + 2^4 + 2^4 + 2^4) = 304
>>
>>8058294
only correct solution
>>
>>8058064
There is 199776 of them.
No real solution, just calculated it programmatically.
https://gist.github.com/anonymous/542af9ab0287019fac3429f285359bce
>>
I would create an adjacency-matrix and multiply it with itself 10 times and finally sum all elements in that matrix. Something along those lines should give all possible words in that language
>>
>>8058422
>>8058307
>>8058284
>>8058283

>6th grade math
>>
>>8058427
But it's not. It's a combinatorics problem whose answer is a large number. 0/10
>>
>>8058064
Where's multi track drifting?
>>
File: 20160508_144845-1.jpg (553 KB, 2089x2393) Image search: [Google]
20160508_144845-1.jpg
553 KB, 2089x2393
>>8058064
>>
>>8058064
Why would anyone pull the lever? I'm saving 100% of the people in the pic by not pulling it.
>>
>>8058388
Correct answer
>>
>>8058388
Easier programmable way to do this however, here it is in rust. It gets the answer recursively.

https://gist.github.com/anonymous/aa63ddafa832ce361161d6909dfd0aa1
>>
and here is my c++ solution:
https://ghostbin.com/paste/z8yyt
it's still running by the time I post this so I don't know if it works jet
>>
>>8059358
I forgot that it has to beginn with a vowel
>>
>>8059358
>using a function call for CtoI instead of a #DEFINE
pleb
>>
>>8058064
>>8058246
Aleph_0 and Aleph_1 are ordinalities not cardinalities. I don't think this question is well posed.
>>
Here is the corrected version of >>8058283

Let
v(n) be the number of words of length n that start with a vowel and end with a vowel.
c(n) be the number of words of length n that start with a vowel and end with a consonant.
Then
v(1) = 2
c(1) = 0
v(n+1) = 2*c(n)
c(n+1) = 3*v(n) + 2*c(n)

Written as matrix this is

[eqn] \left( \begin{matrix} v(n+1) \\ c(n+1) \end {matrix} \right) = \left( \begin{matrix} 1 & 2 \\ 3 & 2 \end{matrix} \right) \left( \begin{matrix} v(n) \\ c(n) \end {matrix} \right) [/eqn]

So the solution is

[eqn] v(10) + c(10) = \left( \begin{matrix} 1 & 1 \end {matrix} \right) \left( \begin{matrix} 0 & 2 \\ 3 & 2 \end{matrix} \right)^{9} \left( \begin{matrix} v(1) \\ c(1) \end {matrix} \right) = \left( \begin{matrix} 1 & 1 \end {matrix} \right) \left( \begin{matrix} 35328 & 43040 \\ 64560 & 78368 \end{matrix} \right) \left( \begin{matrix} 2 \\ 0 \end {matrix} \right) = 199766 [/eqn]
>>
>>8058064
The trolley kills -1/12 people in both scenarios, so it doesn't really matter.
>>
>>8059398
This is incorrect. My bad.
>>
>>8059255
Nice one.
>Easier
Well, my was brute force. To come up with your solution you had to think a little.
But these matches are bad. You don't need to write return in last statement of function and you don't need to use these unreadable ifs inside match.
https://gist.github.com/e779072068bc5a805630014f10b70fff

>>8059358
>using new for tables instead of Vector
>{ 'A', 'B', 'C', 'D', 'E' }; instead of "ABCDE";
>C-like fors instead of C++14 for-in
>generating, storing in huge array and then checking all words instead of doing it while generating
>while(true) without thread yield insdie
Anon, what the fuck.
>>
>>8059479
as you may have noticed I'm new in c++
what is thread yield and what is wrong with my for loops?
(the array thing doesn't make it slower does it?)
>>
>>8059599
while (1) {} can potentially max a core out at 100%, don't do that
>>
>>8059599
You should never use `new` and `delete` in C++ unless you know absolutely what you are doing. You should use shared/unique pointers and/or Vector and/or Array. It will prevents all memory and resource leaks and RAII is much more safer and easier to do.
Your for loops looks ugly and are very vulnerable to bugs.
for(auto el : v){ ...
is more readable and easier than
for(int i=0; i<v.size(); i++){
auto el = v[i]; ...
Using constant instead of v.size is even worse.
Array thing doesn't make it much slower but it makes it use fuck ton of ram.
When you do while(true){} your program will Halt and Catch Fire, ie. will use 100% of processor/core.
You should use while(true){std::this_thread::yield();}. It will tell operating system that you don't have anything to do and will allow other programs to use rest of cpu time.
>>
>>8059599
>>8059619
Also it seems you learned C++ from someone/book who doesn't understand C++11.
Go watch:
https://www.youtube.com/watch?v=xnqTKD8uD64
And then read Meyers S - Effective Modern C++ if you want to use C++ at its full potential.
>>
>>8059619
while(1){} gets removed and similar things get optimized by any compiler from this century
>>
File: 2ec64ce409.png (105 KB, 955x760) Image search: [Google]
2ec64ce409.png
105 KB, 955x760
>>8059635
No it doesn't...
>>
>>8059613
>>8059619
>>8059623
thank you very much guys here is the updated code (it only takes like 27s now before it took like 7min)
https://ghostbin.com/paste/r3yug
>>
>>8059641
I can't get the new for loop working and I'm self-teaching myself sooo...
>>
>>8059640
use the optimization flags then. -o2 is sensible in G++
>>
>>8059657
Are you blind or retarded?
>>
>>8059657
Tell me what, exactly, would while (1) {} "optimize" to?
Thread replies: 55
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.