Skip to main content
Commonmark migration
Source Link

#JavaScript (ES6) 333 331 329 223 characters

JavaScript (ES6) 333 331 329 223 characters

Many thanks to ETHproductions and Neil, 100+ characters thanks to both of you, and I haven't tried findIndex() yet :-)

s=>(d="0,;y\\>|Kb^6 |kn|xw|r?||8MD|hQ|EU|7|2||R|e||||F|||||||||G".split("|"),d[35]="",d[52]="3",d.map((a,j)=>{if(~a.indexOf(String.fromCharCode([...s].reduce((S,c)=>S*32+c.charCodeAt(),0)%153)))o=j}),o+3)

Expanded version

(With \0xx instead of characters)

s => (
    d = "0,;y\\>|Kb^6\t|kn\x1D|\x05\x7F\x84x\bw|r\x12?|\x07\x98|8MD|\x93h\x8E\x11Q|\x8FEU\x1B|7|2|\v|R|\x92e||\x19||\x04F|||||||||\x94G".split("|"),
    d[35] = "\x13",
    d[52] = "3",
    d.map(
        (a,j) => {
            if(~a.indexOf(
                String.fromCharCode([...s].reduce(
                    (S,c)=>S*32+c.charCodeAt(),0)%153)
                ))
                o = j
        }
    ),
    o+3
)

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

#JavaScript (ES6) 333 331 329 223 characters

Many thanks to ETHproductions and Neil, 100+ characters thanks to both of you, and I haven't tried findIndex() yet :-)

s=>(d="0,;y\\>|Kb^6 |kn|xw|r?||8MD|hQ|EU|7|2||R|e||||F|||||||||G".split("|"),d[35]="",d[52]="3",d.map((a,j)=>{if(~a.indexOf(String.fromCharCode([...s].reduce((S,c)=>S*32+c.charCodeAt(),0)%153)))o=j}),o+3)

Expanded version

(With \0xx instead of characters)

s => (
    d = "0,;y\\>|Kb^6\t|kn\x1D|\x05\x7F\x84x\bw|r\x12?|\x07\x98|8MD|\x93h\x8E\x11Q|\x8FEU\x1B|7|2|\v|R|\x92e||\x19||\x04F|||||||||\x94G".split("|"),
    d[35] = "\x13",
    d[52] = "3",
    d.map(
        (a,j) => {
            if(~a.indexOf(
                String.fromCharCode([...s].reduce(
                    (S,c)=>S*32+c.charCodeAt(),0)%153)
                ))
                o = j
        }
    ),
    o+3
)

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

JavaScript (ES6) 333 331 329 223 characters

Many thanks to ETHproductions and Neil, 100+ characters thanks to both of you, and I haven't tried findIndex() yet :-)

s=>(d="0,;y\\>|Kb^6 |kn|xw|r?||8MD|hQ|EU|7|2||R|e||||F|||||||||G".split("|"),d[35]="",d[52]="3",d.map((a,j)=>{if(~a.indexOf(String.fromCharCode([...s].reduce((S,c)=>S*32+c.charCodeAt(),0)%153)))o=j}),o+3)

Expanded version

(With \0xx instead of characters)

s => (
    d = "0,;y\\>|Kb^6\t|kn\x1D|\x05\x7F\x84x\bw|r\x12?|\x07\x98|8MD|\x93h\x8E\x11Q|\x8FEU\x1B|7|2|\v|R|\x92e||\x19||\x04F|||||||||\x94G".split("|"),
    d[35] = "\x13",
    d[52] = "3",
    d.map(
        (a,j) => {
            if(~a.indexOf(
                String.fromCharCode([...s].reduce(
                    (S,c)=>S*32+c.charCodeAt(),0)%153)
                ))
                o = j
        }
    ),
    o+3
)

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

deleted 41 characters in body
Source Link

#JavaScript (ES6) 333 331 329 bytes329 223 characters

Many thanks to ETHproductions and Neil, 100+ characters thanks to both of you, and I haven't tried findIndex() yet :-)

s=>{d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25](d="0,;y\\>|Kb^6 |kn|xw|r?||8MD|hQ|EU|7|2||R|e||||F|||||||||G".split("|"),[4d[35]="",70]];d[26]=[148d[52]="3",71];d[35]=[19];d[52]=[51];dd.map((a,j)=>{if(a&&~a~a.indexOf(sString.splitfromCharCode('')[...s].reduce((S,c)=>S*32+c.charCodeAt(0),0)%153)))o=j});return ,o+3};)

Expanded version

(With \0xx instead of characters)

s => {(
    d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],d = "0,[4;y\\>|Kb^6\t|kn\x1D|\x05\x7F\x84x\bw|r\x12?|\x07\x98|8MD|\x93h\x8E\x11Q|\x8FEU\x1B|7|2|\v|R|\x92e||\x19||\x04F|||||||||\x94G".split("|"),70]];
    d[26]=[148,71];
d[35] = "\x13",
  d[35]=[19];
  d[52] = d[52]=[51];"3",
    d.map(
        (a,j)=> a=> &&{
             if(~a.indexOf(s
                String.splitfromCharCode('')[...s].reduce(
                    (S,c)=>S*32+c.charCodeAt(0),0) %153) 
 &&               ))
              o=j  o = j
        });
    return),
    o+3
};)

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

#JavaScript (ES6) 333 331 329 bytes

s=>{d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];d[26]=[148,71];d[35]=[19];d[52]=[51];d.map((a,j)=>{if(a&&~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153))o=j});return o+3};

Expanded version

s => {
    d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];
    d[26]=[148,71];
    d[35]=[19];
    d[52]=[51];
    d.map( (a,j)=> a &&
             ~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0) %153) &&
              o=j
    });
    return o+3
};

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

#JavaScript (ES6) 333 331 329 223 characters

Many thanks to ETHproductions and Neil, 100+ characters thanks to both of you, and I haven't tried findIndex() yet :-)

s=>(d="0,;y\\>|Kb^6 |kn|xw|r?||8MD|hQ|EU|7|2||R|e||||F|||||||||G".split("|"),d[35]="",d[52]="3",d.map((a,j)=>{if(~a.indexOf(String.fromCharCode([...s].reduce((S,c)=>S*32+c.charCodeAt(),0)%153)))o=j}),o+3)

Expanded version

(With \0xx instead of characters)

s => (
    d = "0,;y\\>|Kb^6\t|kn\x1D|\x05\x7F\x84x\bw|r\x12?|\x07\x98|8MD|\x93h\x8E\x11Q|\x8FEU\x1B|7|2|\v|R|\x92e||\x19||\x04F|||||||||\x94G".split("|"),
    d[35] = "\x13",
    d[52] = "3",
    d.map(
        (a,j) => {
            if(~a.indexOf(
                String.fromCharCode([...s].reduce(
                    (S,c)=>S*32+c.charCodeAt(),0)%153) 
                ))
                o = j
        }
    ),
    o+3
)

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

deleted 12 characters in body
Source Link

###EDIT:

#JavaScript (ES6) 335333 333331 331329 bytes

v=s=>s=>{d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];d[26]=[148,71];d[35]=[19];d[52]=[51];d.map((a,j)=>{if(a&&~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153))o=j});return o+3};

Usage:

v("New York")

Expanded version

v= s => {
    d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];
    d[26]=[148,71];
    d[35]=[19];
    d[52]=[51];
    d.map( (a,j)=> a &&
             ~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0) %153) &&
              o=j
    });
    return o+3
};

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

###EDIT:

#JavaScript (ES6) 335 333 331 bytes

v=s=>{d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];d[26]=[148,71];d[35]=[19];d[52]=[51];d.map((a,j)=>{if(a&&~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153))o=j});return o+3};

Usage:

v("New York")

Expanded version

v= s => {
    d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];
    d[26]=[148,71];
    d[35]=[19];
    d[52]=[51];
    d.map( (a,j)=> a &&
             ~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0) %153) &&
              o=j
    });
    return o+3
};

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

#JavaScript (ES6) 333 331 329 bytes

s=>{d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];d[26]=[148,71];d[35]=[19];d[52]=[51];d.map((a,j)=>{if(a&&~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153))o=j});return o+3};

Expanded version

s => {
    d=[[48,44,59,121,92,62],[75,98,94,54,9],[107,110,29],[5,127,132,120,8,119],[114,18,63],[7,152],[56,77,68],[147,104,142,17,81],[143,69,85,27],[55],[50],[11],[82],[146,101],,[25],,[4,70]];
    d[26]=[148,71];
    d[35]=[19];
    d[52]=[51];
    d.map( (a,j)=> a &&
             ~a.indexOf(s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0) %153) &&
              o=j
    });
    return o+3
};

Approach:

Preprocessing:

Calculate an hash of each state name and store them in an array where one dimension is the number of votes the state has.

Processing:

Recalculate the hash and retrieve the information.

An hash of a state name is calculated with s.split('').reduce((S,c)=>S*32+c.charCodeAt(0),0)%153.

It transform "Iowa" in (32^3*'I' + 32^2*'o' + 32*'w' + 'a')%153 (with ascii value for characters).

Why 32 and 153? Because after a few empiric tests those values minimize hashes without collision between states that have different number of votes.

I don't believe that it will be hard to do something shorter with a better approach but since I spent a few time on it ;).

Remove if; added 5 characters in body
Source Link
Loading
improved formatting
Source Link
Loading
Add expanded version
Source Link
Loading
Post Undeleted by Pandawan
Had misunderstood the question
Source Link
Loading
Post Deleted by Pandawan
Source Link
Loading