Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c38dd3

Browse files
committed
02 - Haskell
1 parent74c601d commit0c38dd3

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

‎2018/02_1/haskell/appositum.hs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
importData.Map (Map)
2+
importqualifiedData.MapasM
3+
importSystem.Environment
4+
5+
typeDict=MapIntChar
6+
7+
main::IO()
8+
main=do
9+
args<- getArgs
10+
case argsof
11+
[]->putStrLn"Usage: ./appositum input.txt"
12+
(arg:_)->readFile arg>>=print. checksum.lines
13+
14+
count::Eqa=>a-> [a]->Int
15+
count el=length.filter (==el)
16+
17+
zipped::String->Dict
18+
zipped xs=M.fromList$map (\x-> (count x xs, x)) xs
19+
20+
twos::Dict->Dict
21+
twos=M.filterWithKey (\k _-> k==2)
22+
23+
threes::Dict->Dict
24+
threes=M.filterWithKey (\k _-> k==3)
25+
26+
checksum:: [String]->Int
27+
checksum strings=length threes'*length twos'where
28+
get f=filter (/=M.empty)$map (f. zipped) strings
29+
threes'= get threes
30+
twos'= get twos

‎2018/02_2/haskell/appositum.hs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
importSystem.Environment
2+
3+
main::IO()
4+
main=do
5+
args<- getArgs
6+
case argsof
7+
[]->putStrLn"Usage: ./appositum input.txt"
8+
(arg:_)->readFile arg>>=putStrLn. common.lines
9+
10+
common strs= common' x ywhere
11+
[x,y]= [x| x<- strs, y<- strs, exactlyOne x y]
12+
13+
common'"" _=""
14+
common' _""=""
15+
common' (x:xs) (y:ys)
16+
| x== y= x: common' xs ys
17+
|otherwise= common' xs ys
18+
19+
exactlyOne xs ys=length filtered==1where
20+
filtered=filter (not.snd)$
21+
zipWith (\x y-> (x, x== y)) xs ys

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp