Help us understand the problem. What is going on with this article?

F#で安藤杏ちゃんの好感度をMAX&レアアイテムALL GET (POH7)

More than 3 years have passed since last update.

プログラミングで彼女を作る(paiza Online Hackathon 7)の言語別集計数を見ると、F#で提出している人が少ないようでしたので、一通りF#で書いてみました。
こうした方が良い、等のご指摘は大歓迎です。いつでもお待ちしております。

つり目

seq { for n in 1 .. int (System.Console.ReadLine()) -> "Ann" }
|> Seq.reduce (+)
|> printfn "%s"

眼帯

open System

ignore (Console.ReadLine())
ignore (Console.ReadLine())

let a = Console.ReadLine().Split(' ')
        |> Set.ofArray

ignore (Console.ReadLine())

let b = Console.ReadLine().Split(' ')
        |> Set.ofArray

let c = b - a
printfn "%s" (if (Set.isEmpty c) then "None" else c |> Set.toSeq
                                                    |> Seq.sortBy (fun elem -> int (elem))
                                                    |> Seq.reduce (fun acc elem -> acc + " " + elem))

ソートするのを忘れていてハマりました。

ショートヘア

printfn "%d" (int (System.Console.ReadLine()) + int (System.Console.ReadLine()))

ロングヘア

let ans =
    seq { for n in 1 .. 5 -> System.Console.ReadLine() }
    |> Seq.fold (fun acc elem -> acc + match elem with
                                        | "yes" -> 1
                                        | "no" -> 0) 0
printfn "%s" (if ans > 2 then "yes" else "no")

ポニーテール

[ 1 .. int (System.Console.ReadLine()) ]
|> List.rev
|> List.iter (fun elem -> printfn "%d" elem)
printfn "0!!"

ツインテール

open System

let cp (s : string) =
    let arr = s.Split(' ')
    float (arr.[0]) / float (arr.[1])

let ret1 = cp (Console.ReadLine())
let ret2 = cp (Console.ReadLine())
printfn "%s" (if ret1 > ret2 then "1" else "2")

セーラー服

open System

seq { for n in 1 .. int (Console.ReadLine()) -> Console.ReadLine() }
|> Seq.reduce (fun acc elem -> acc + "_" + elem)
|> printfn "%s"

カーディガン

seq { 1 .. int (System.Console.ReadLine()) }
|> Seq.reduce (*)
|> printfn "%d"

縞ニーソ

open System

let n = int (Console.ReadLine())
seq { for i in 1 .. int (Console.ReadLine()) -> match (i - 1) % (2 * n) with
                                                | _ as c when c < n -> "R"
                                                | _ as c when c >= n -> "W" }
|> Seq.iter (fun elem -> printf "%s" elem)

レアアイテム

めがね

open System

let n = int (Console.ReadLine())
let large = Array.zeroCreate<string[]> n
            |> Array.map (fun elem -> Console.ReadLine().Split(' '))

let m = int (Console.ReadLine())
let small = Array.zeroCreate<string[]> m
            |> Array.map (fun elem -> Console.ReadLine().Split(' '))

let mutable res = (0, 0)
for i in 0 .. (n - m) do
    for j in 0 .. (n - m) do
        let mutable flag = true

        for k in 0 .. (m - 1) do
            for l in 0 .. (m - 1) do
                 if large.[i + k].[j + l] <> small.[k].[l] then flag <- false

        if flag then res <- (i, j)

printfn "%d %d" (fst (res)) (snd (res))

宣言型に近いコードになってしまいました。

サンタ服

open System

let xyzn = Console.ReadLine().Split(' ')

let mutable xlist = [ 0; ]
let mutable ylist = [ 0; ]

for i in 1 .. int (xyzn.[3]) do
    let s = Console.ReadLine().Split(' ')
    let v = int (s.[1])
    if s.[0] = "0" then xlist <- v :: xlist else ylist <- v :: ylist

xlist <- int (xyzn.[0]) :: xlist
         |> List.sort

let mutable xslist = []
for i in 0 .. (xlist.Length - 2) do
    xslist <- (xlist.Item(i + 1) - xlist.Item(i)) :: xslist

xslist <- List.sort xslist

ylist <- int (xyzn.[1]) :: ylist
         |> List.sort

let mutable yslist = []
for i in 0 .. (ylist.Length - 2) do
    yslist <- (ylist.Item(i + 1) - ylist.Item(i)) :: yslist

yslist <- List.sort yslist

printfn "%d" (xslist.Head * yslist.Head * int (xyzn.[2]))

これも宣言型に近いコードになってしまいました。

水着

(seq { 1L .. int64 (System.Console.ReadLine()) }
|> Seq.reduce (fun acc elem -> 
               let rec re n = if n % 10L = 0L then re (n / 10L) else n
               re (acc * elem) % 100000000000L)) % 1000000000L
|> printfn "%d"

計算途中では、9桁ではなく11桁取る必要がある、と言うことに気付かず苦戦しました。

dc1394
主にC++とC#を使っています。数値解析が趣味。 博士後期課程中退。専門は第一原理計算。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした