fork download
  1. (* not in 4.01 stdlib *)
  2. let list_of_string s =
  3. let rec los i acc =
  4. if i >= String.length s then acc
  5. else let ch = String.get s i in
  6. los (i + 1) (ch :: acc)
  7. in
  8. List.rev @@ los 0 []
  9.  
  10. let permissions s = list_of_string s
  11. |> List.map (function
  12. | '-' -> 0
  13. | 'r' | 'w' -> 1
  14. | _ -> raise @@ Invalid_argument "shit happened")
  15. |> List.fold_left (fun acc cur -> (acc lsl 1) lor cur) 0
  16.  
  17. let ss = "-rw-rw-r--"
  18. let () = print_endline @@ string_of_int @@ permissions ss
Success #stdin #stdout 0s 4224KB
stdin
Standard input is empty
stdout
436