Just algorithm!
Alien Numbers



¹ blog ҹҹҡ

ҵ͹ͧСͺ 3 ҧ

1. 觾Ҵ join codejam µͧ֡ͻ˹

2. ѧѴ¹ f#

3. ǧҹ͹ҧ ҡ



µ solve codejam f# ¹ blog 仴



á Alien Numbers

⨷ յŢҵҧ 2 ش ŨҡŢҹ֧աҹ֧



Ţúԡ 0123456789 ҧŢ hex 0123456789abcdef

ѧŢ 10 ҡѺ a



ҧ͹ 0-9 ͧҨ )!@#$%^&*(

ѡùѺ͹Ţͧءҧ

ҹ´ Ѻ



⨷͹ҧҡ ѡŢҹʺ

ԸդԴŨҡá int ͹ Ǩҡ int ҷͧ



ҡ function ѡ

letsolvevaluetxt1txt2=

function solve

value Ţͧ foo

txt1 شŢͧŢͧ of8

txt2 شŢաҹ֧ ҵͧҹ 0123456789

value type string ǹ txt1 Ѻ txt2 char[]



function Ũҡ txt1 int

lettxtToNumtxtv=
letbaseN=Array.lengthtxt
letfoldFnab=a*baseN+Array.IndexOf(txt,b)
Seq.foldfoldFn0v

baseN ӹǹŢҹ of8 Ţҹ 3

foldFn ٵáäӹǹŢҹ int

Ţ͹˹ (a) x Ţҹ (baseN) + Ңͧѡù



Ţ foo ҡ of8

¶ҹѺ˹ f ҡѺ 1 ǹ o ҡѺ 0

f = 1

fo = 1 * 3 + 0 = 3

foo = 3 * 3 + 0 = 9

ѧ foo = 9



function Ũҡ int txt2

letnumToTxttxtv=
letbaseN=Array.lengthtxt
letunfoldFn=function
|-1->None
|n->matchMath.DivRem(n,baseN)with
|0,r->Some(r,-1)
|d,r->Some(r,d)
v|>Seq.unfoldunfoldFn
|>Enumerable.Reverse
|>Seq.map(Array.gettxt)
|>Seq.mapstring
|>String.Concat

unfoldFn function Ţ int Ţҹ

Ţ 454 еͧŢҹ 6



454 / 6 75 4

75 / 6 12 3

12 / 6 2 0

2 / 6 0 2



Ҩ 4,3,0,2 Ѿͧҹ͹ѧ

µͧ call Enumerable.Reverse 2,0,3,4

Seq.map (Array.get txt) ͡ map Ѻաشѡ

2,0,3,4 map Ѻ A?JM!. С J,A,M,!



Seq.map string Ѻ String.Concat ŧ string

ҡ J,A,M,! JAM!



¡ function

value|>txtToNumtxt1
|>numToTxttxt2

¹ value txtToNum ҼѾ numToTxt









Create Date : 03 Ҥ 2557
Last Update : 27 Ҥ 2557 12:08:33 . 0 comments
Counter : 512 Pageviews.

:
Comment :
  * code html 觢ͤ੾Ҫԡ
 
觢ͤ
س׹ѹ觢ͤ

chaowman
Location :
ا෾ Thailand

[Profile ]

ԻҢͧ Blog [?]
ҡͤѧ
Rss Feed
Smember
Դ͡ : 8 [?]









New Comments
Group Blog
 
All Blogs
 
Friends' blogs
[Add chaowman's blog to your web]
Links
 

 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.