SNOWMAN's Dictionary !

The letters of the word:

S N O W M A N \mathbb{ SNOWMAN }

are re-arranged to form a dictionary where :

1.Only 7 7 lettered words are included .

2.Words are arranged alphabetically.

Then, find the sum of the digits of the position of S N O W M A N \mathbb{ SNOWMAN } in the dictionary.


The answer is 6.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

9 solutions

Bhargav Das
Dec 16, 2013

First, we need to find the no. of words starting with A and there are 6 ! 2 \frac{6!}{2} (Since,there are 2 N's )

Then,no. of words starting with M of which there are 6 ! 2 \frac{6!}{2}

Then,no. of words starting with N of which there are 6 ! 6!

Then,no. of words starting with O of which there are 6 ! 2 \frac{6!}{2}

Then,no. of words starting with SA of which there are 5 ! 2 \frac{5!}{2}

Then,no. of words starting with SM of which there are 5 ! 2 \frac{5!}{2}

Then,no. of words starting with SNA of which there are 4 ! {4!}

Then,no. of words starting with SNM of which there are 4 ! 4!

Then,no. of words starting with SNN of which there are 4 ! 4!

Then,no. of words starting with SNOA of which there are 3 ! 3!

Then,no. of words starting with SNOM of which there are 3 ! 3!

Then,no. of words starting with SNON of which there are 3 ! 3!

We get a total of 2010 2010 words so far.

Now,we have to count words starting with SNOW till we get our desired word SNOWMAN .

We see first word starting with SNOW is SNOWAMN ,then SNOWANM and then SNOWMAN or that our desired word is the 2013 t h 2013th word in the dictionary. Hence, our answer is 2 + 0 + 1 + 3 = 6 2+0+1+3=\boxed{6} .

Behold the power of Stephen Wolfram

Position[#,"SNOWMAN"]&@SortBy[#,First]/@(StringJoin/@Permutations@Characters["SNOWMAN"])

Josh Silverman Staff - 7 years, 5 months ago

Anyone notice how the answer is 2013 :P?

Also, notice the SA

minimario minimario - 7 years, 5 months ago

Log in to reply

Can you tell me what's so special about SA?

Bhargav Das - 7 years, 5 months ago

Log in to reply

sa

Ryan Soedjak - 7 years, 5 months ago

Log in to reply

@Ryan Soedjak sa

Daniel Liu - 7 years, 5 months ago

Log in to reply

@Daniel Liu sa

Ryan Soedjak - 7 years, 5 months ago

Log in to reply

@Ryan Soedjak SA ??

Sanjay Banerji - 7 years, 5 months ago

@Ryan Soedjak sa

Akshat Jain - 7 years, 5 months ago

sa

Daniel Liu - 7 years, 5 months ago

Log in to reply

@Daniel Liu sa

Ryan Soedjak - 7 years, 5 months ago

@Daniel Liu SA ??

Sanjay Banerji - 7 years, 5 months ago

TOT Senior A-level Paper. :)

Zi Song Yeoh - 7 years, 5 months ago

Log in to reply

@Zi Song Yeoh sa

Ryan Soedjak - 7 years, 5 months ago

I got this wrong, because obviously 2 + 0 + 1 + 3 = 5 2+0+1+3=\boxed{5} . I used my other two tries because I misunderstood the question. At first I thought any letter could be in the dictionary, then I thought words like "AAAAAAA" are okay since "A" is in "SNOWMAN". The question could be worded better.

Anyway, nice job working 2013 in.

Daniel Chiu - 7 years, 5 months ago

Log in to reply

Coincidence

Priyansh Sangule - 7 years, 5 months ago

Extremely explanatory :D

Priyansh Sangule - 7 years, 5 months ago

Log in to reply

Very nice work getting "2013" in. Was that on purpose or a pleasant coincidence?

Daniel Liu - 7 years, 5 months ago

Log in to reply

Pleasant Coincidence lol.

Priyansh Sangule - 7 years, 5 months ago

Did the same!!

Tanya Gupta - 7 years, 2 months ago
Thaddeus Abiy
Dec 17, 2013

Can be done rather easily in python

from itertools import permutations as perm
print sorted(set(perm([i for i in 'SNOWMAN']))).index(tuple((i for i in 'SNOWMAN')))+1

I also used the itertools module in python

Eddie The Head - 7 years, 5 months ago

Here is an even shorter version of your code.

from itertools import permutations as perm
print sorted(set(perm('snowman'))).index(tuple('snowman'))+1

Isaí Vázquez - 7 years, 4 months ago

Log in to reply

Cool..Didn't know the tuple function accepted str's

Thaddeus Abiy - 7 years, 4 months ago
Aamira Shabnam
Dec 22, 2013

JAVA CODE:

public class Permutations {

static int count = 0;
static List list = new ArrayList();
static LinkedHashSet lhs = new LinkedHashSet();

public static void perm(String s) {
    perm("", s);

}

private static void perm(String prefix, String s) {
    int N = s.length();
    if (N == 0) {
        lhs.add(prefix);

    } else {
        for (int i = 0; i < N; i++) {
            perm(prefix + s.charAt(i), s.substring(0, i) + s.substring(i + 1, N));

        }
    }


}

private static void swap(char[] a, int i, int j) {
    char c;
    c = a[i];
    a[i] = a[j];
    a[j] = c;
}

public static void main(String[] args) {

    String str = "snowman";
    char[] ca = str.toCharArray();
    Arrays.sort(ca);
    str = new String(ca);

    perm(str);

    list = Arrays.asList(lhs.toArray());

    int count = list.indexOf("snowman");
    System.out.println(count);

    Integer pr = (Integer) count+1;
    String string = pr.toString();
    char[] arr = string.toCharArray();


    int sum = 0;
    for (int i = 0; i < arr.length; i++) {
        sum += (arr[i] - 48);
    }
    System.out.println(sum);

}

}

Stefan Stankovic
Dec 18, 2013

In Mathematica:

Position[Sort[Permutations[{s, n, o, w, m, a, n}]], {s, n, o, w, m, a, n}]

2013
Anis Abboud
Dec 16, 2013

Probably the best way to do this is combinatorially, but I was too lazy to go over all the options and sum them up, so I wrote the following piece of code.

def generateWords(letters):
    if len(letters) == 1:
        return [letters]

    result = []
    for i, letter in enumerate(letters):
        result += [letter + subword for subword in generateWords(letters[:i] + letters[i + 1:])]
    return result

words = sorted(set(generateWords('SNOWMAN')))
print words.index('SNOWMAN') + 1

generateWords(letters) is a recursive function that generate all the possible permutations of the given string. I call it with the string 'SNOWMAN', and as there are to 'N's, there could be duplicates, so I wrap the result with set() to remove duplicates.

Finally, I sort the dictionary of words, and find the index of 'SNOWMAN', which is 2012 zero-based, so 2013 1-based. 2 + 0 + 1 + 3 = 6 2+0+1+3 = \boxed{6} .

Lokesh Sharma
Feb 5, 2014

Python Solution:

import itertools
a = list(itertools.permutations('SNOWMAN'))
b = [''.join(i) for i in a]
b.sort()
c = []
for i in b:
    if i not in c:
        c.append(i)
print c.index('SNOWMAN') + 1

This can be solved more cleverly, but since our alphabet size is small enough, we can simply generate all the permutations and find the position of the word "SNOWMAN" there. Here's a fairly short C++ implementation:

string start = "AMNNOSW";
vector<string> words;

int main()
{
    do
    {
        words.push_back(start);
    } while (next_permutation(start.begin(), start.end()));
    int ret = 1;
    for (;words[ret-1] != "SNOWMAN";ret++);
    printf("%d\n",ret);
}

Calling this code returns 2013, and hence the sum of digits is 6.

Brian Chen
Dec 20, 2013

Naive Haskell

import Data.List
import Data.Char
import Data.Maybe
main = print $ sum $ map digitToInt $ show $ (1+) $ fromJust $ elemIndex "snowman" $ nub $ sort $ permutations "snowman"

But obviously this is asymptotically suboptimal. To provide some motivation to get a faster and more general solution, and put the coincidence of 2013 in context, let's find all words that are 2013rd in their respective dictionaries. The obvious way to speed things up is not to list all permutations that start with prefixes we don't want, but just count them with factorials. Several other solutions have demonstrated the process, so here's code:

import Data.Char
import Data.List
import Data.Maybe
import Control.Applicative

factorial n = product [1..n]

-- Given a list of frequencies of objects, count permutations of said objects
groupPerms fs = factorial (sum fs) `quot` product (map factorial fs)

-- Splice out one copy of an element
spliceOutFrom [] _ = error "spliceOutFrom failed"
spliceOutFrom (x:xs) t
    | x == t    = xs
    | otherwise = x : spliceOutFrom xs t

-- Given a word, count how many permutations it has
lexCount ss = groupPerms $ map length $ group $ sort ss

-- Given a word, figure out its (0-based) index in a lexicographical dictionary of its permutations
lexIndex [] = 0
lexIndex [x] = 0
lexIndex (x:xs) = (sum $ map (lexCount . spliceOutFrom (x:xs)) $ filter (< x) $ nub $ sort xs) + lexIndex xs

main = putStrLn =<< unlines . filter ((== 2012) . lexIndex) . words <$> getContents

Feeding this the SOWPODS lexicon results in the list:

  • ARBOREAL
  • CONFINER
  • CONFINES
  • CULTURES
  • EUSTYLES
  • OUTVIES
  • OUTWEAR
  • SKIVIER
  • SNOWMAN
  • SNOWMEN
  • TERTIAL
  • TERTIAN
  • UNTURFS
  • UPTURNS

This being out of a lexicon with 32909 seven-letter words and 40161 eight-letter words, it's not a trivial coincidence. (But then, "SNOWING" would work for next year's Christmas too.)

Brian Chen - 7 years, 5 months ago
Pi Han Goh
Dec 18, 2013

Motivation : I first find the total number of ways to arrange the word, which is 2520 2520 . Because the words are written in alphabetical order, and next to W \mathbb{W} , the second last alphabet is S \mathbb{S} . So by working backwards, I counted the number of words that begins with W \mathbb{W} , call it x x . Now we know that somewhere between 2520 x 2520 - x . Now, we have correctly placed the letter S \mathbb{S} in the first position. And because we're working backwards, we consider the letter W \mathbb{W} as the second letter and apply the same logic, and so on til we get the word S N O W M A N \mathbb{SNOWMAN}

We note the total number of ways total arrange S N O W M A N \mathbb{SNOWMAN} is 7 ! 2 ! = 2520 \frac {7!}{2!} = 2520

We know that W \mathbb{W} is the last in the alphabets (in the list). So if the position starts with W \mathbb{W} , then the last ( 7 1 ) ! 2 ! = 360 \frac {(7-1)!}{2!} = 360 words begins with W \mathbb{W} .

"Counting backwards", for words starting with S W \mathbb{SW} there is a total 5 ! 2 ! = 60 \frac {5!}{2!} = 60 words.

And for words starting with S O \mathbb{SO} there is a total 5 ! 2 ! = 60 \frac {5!}{2!} = 60 words.

Again, for words starting with S N W O \mathbb{SNWO} , there is a total of 3 ! = 6 3! = 6 words.

2520 360 60 60 6 = 2034 2520 - 360 - 60 - 60 - 6 = 2034

Thus

The word S N O W N M A \mathbb{SNOWNMA} is the 203 4 th 2034^{\text{th}} position

The word S N O W N A M \mathbb{SNOWNAM} is the 203 3 rd 2033^{\text{rd}} position

The word S N O W M N A \mathbb{SNOWMNA} is the 203 2 nd 2032^{\text{nd}} position

The word S N O W M A N \mathbb{SNOWMAN} is the 203 1 st 2031^{\text{st}} position

Hence, the answer is 2 + 0 + 3 + 1 = 6 2 + 0 + 3 + 1 = \boxed{6}

IGNORE THIS ANSWER. I'VE MADE AN ERROR!

Pi Han Goh - 7 years, 5 months ago

Log in to reply

You forgot the double counting of N \mathbb{N} silly!

Pi Han Goh - 7 years, 5 months ago

Log in to reply

Yeah, Bhargav Das' answer is simpler. Thanks for pointing out my mistake.

Pi Han Goh - 7 years, 5 months ago

Log in to reply

@Pi Han Goh No problem. =D

Pi Han Goh - 7 years, 5 months ago

Log in to reply

@Pi Han Goh Um... Are you talking to yourself?

Daniel Liu - 7 years, 5 months ago

Log in to reply

@Daniel Liu no, the other one deleted his post :P

Anas Elidrissi - 7 years, 5 months ago

@Daniel Liu wkwkwkw

pebrudal zanu - 7 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...