Tag Archives: 代考

CS计算机代考程序代写 val rev_tup : ‘a * ‘b * ‘c -> ‘c * ‘b * ‘a

val rev_tup : ‘a * ‘b * ‘c -> ‘c * ‘b * ‘a
val abs : int -> int
val area : int * int -> int * int -> int
val volume : int * int * int -> int * int * int -> int
val fibonacci : int -> int
val pow : int -> int -> int
val log : int -> int -> int
val is_prime : int -> bool
val next_prime : int -> int
val get : int -> ‘a list -> ‘a
val larger : ‘a list -> ‘a list -> ‘a list
val reverse : ‘a list -> ‘a list
val combine : ‘a list -> ‘a list -> ‘a list
val rotate : int -> ‘a list -> ‘a list
val is_palindrome : ‘a list -> bool

CS计算机代考程序代写 ocaml ## How to use utop

## How to use utop

Utop is an incredibly useful tool to have when you’re writing OCaml. If you
don’t already have it, you can install it through opam (`opam install utop`).
Here’s a few tips you might find useful.

Utop is based off the original toplevel for OCaml, which you can use by just
running `ocaml`. However, the default toplevel is very sparse in features – it
doesn’t even remember previous inputs.

### Quitting
To quit utop, input `CTRL-D`. You can also enter `#quit;;`.

### Colors
Utop has support for syntax highlighting. To set it up, see
[here](https://github.com/ocaml-community/utop#colors).

### Loading in a file
Assume you have a file called `foo.ml` with the following contents:
“`ocaml
let is_positive n =
n > 0
“`

You can use it in utop with `#use`:
“`ocaml
utop # #use “foo.ml”;;
val is_positive : int -> bool =

utop # is_positive 4;;
– : bool = true
“`

You can also use `#mod_use` to keep it within the Foo module:
“`ocaml
utop # #mod_use “foo.ml”;;
module Foo : sig val is_positive : int -> bool end

utop # Foo.is_positive (-10);;
– : bool = false
“`

### Dune
`#use` works well for small, self-contained modules. However, if a module
depends on other modules, they will all have to be loaded in order, which can be
tedious. Thankfully, all of our projects use [dune](https://dune.build) to
compile. Dune will automatically resolve any dependencies between modules.

If you have several related modules in a directory called `src`
(like all of our projects do), you can start utop with them loaded by running
“`sh
dune utop src
“`
from the project’s directory.

The functions will be contained in modules, named after the files. For example,
in project 2A, all the functions will be in the `Basics` module.

### Saving your work
If you want to save what you’ve done for later, you can use `#utop_stash`.
This will save the commands you entered, alongside their output. The output
will be commented, so the end result is still a valid OCaml file.

For example, to save your work to a file called `stuff.ml`:
“`ocaml
utop # #utop_stash “stuff.ml”;;
“`

### Further reading
– [UTop homepage](https://github.com/ocaml-community/utop)
– [Manual for the default toplevel](http://caml.inria.fr/pub/docs/manual-ocaml/toplevel.html) – Most of what’s written here also applies to utop.

CS计算机代考程序代写 database (*The following functions have been provided

(*The following functions have been provided
for your convenience*)

let rec map f xs = match xs with
| [] -> []
| x :: xt -> (f x)::(map f xt)

let rec foldl f a xs = match xs with
| [] -> a
| x :: xt -> foldl f (f a x) xt

let rec foldr f xs a = match xs with
| [] -> a
| x :: xt -> f x (foldr f xt a)

(* You may want to use these functions for stalin_sort_right *)
let rec rev lst = match lst with
| [] -> []
| x :: xt -> (rev xt) @ [x]

let rec get_last_element lst =
match lst with
| [x] -> x
| _ :: xt -> get_last_element xt
| [] -> failwith “empty list has no elements”

(*This record type will be used for the
update_database problem*)
type student_information =
{
name : string;
age : int;
gpa : float;
}

(*Implement these functions*)
let mul_thresh lst thresh =
failwith “unimplemented”

let multi_map f lst =
failwith “unimplemented”

let update_database lst =
failwith “unimplemented”

let stalin_sort lst =
failwith “unimplemented”

let stalin_sort_right lst =
failwith “unimplemented”

CS计算机代考程序代写 open Funs

open Funs

(*************************************)
(* Part 2: Three-Way Search Tree *)
(*************************************)

type int_tree =
| IntLeaf
| IntNode of int * int option * int_tree * int_tree * int_tree

let empty_int_tree = IntLeaf

let rec int_insert x t =
failwith “unimplemented”

let rec int_mem x t =
failwith “unimplemented”

let rec int_size t =
failwith “unimplemented”

let rec int_max t =
failwith “unimplemented”

(*******************************)
(* Part 3: Three-Way Search Tree-Based Map *)
(*******************************)

type ‘a tree_map =
| MapLeaf
| MapNode of (int * ‘a) * (int * ‘a) option * ‘a tree_map * ‘a tree_map * ‘a tree_map

let empty_tree_map = MapLeaf

let rec map_put k v t =
failwith “unimplemented”

let rec map_contains k t =
failwith “unimplemented”

let rec map_get k t =
failwith “unimplemented”

(***************************)
(* Part 4: Variable Lookup *)
(***************************)

type lookup_table = (string * int) list list

let empty_table = []

let push_scope (table:lookup_table) : lookup_table =
failwith “unimplemented”

let pop_scope (table:lookup_table) : lookup_table =
failwith “unimplemented”

let var_exists name scope =
failwith “unimplemented”

let add_var name value (table:lookup_table) : lookup_table =
failwith “unimplemented”

let rec lookup name (table:lookup_table) =
failwith “unimplemented”

CS计算机代考程序代写 require_relative ‘../models/game_board’

require_relative ‘../models/game_board’
require_relative ‘../models/ship’
require_relative ‘../models/position’

# return a populated GameBoard or nil
# Return nil on any error (validation error or file opening error)
# If 5 valid ships added, return GameBoard; return nil otherwise
def read_ships_file(path)
GameBoard.new 10, 10
end

# return Array of Position or nil
# Returns nil on file open error
def read_attacks_file(path)
[Position.new(1, 1)]
end

# ===========================================
# =====DON’T modify the following code=======
# ===========================================
# Use this code for reading files
# Pass a code block that would accept a file line
# and does something with it
# Returns True on successfully opening the file
# Returns False if file doesn’t exist
def read_file_lines(path)
return false unless File.exist? path
if block_given?
File.open(path).each do |line|
yield line
end
end

true
end

CS计算机代考程序代写 class GameBoard

class GameBoard
attr_reader :max_row, :max_column

def initialize(max_row, max_column)
@max_row = max_row
@max_column = max_column
end

# adds a Ship object to the GameBoard
# returns Boolean
# Returns true on successfully added the ship, false otherwise
# Note that Position pair starts from 1 to max_row/max_column
def add_ship(ship)
true
end

# return Boolean on whether attack was successful or not (hit a ship?)
# return nil if Position is invalid (out of the boundary defined)
def attack_pos(position)
# check position

# update your grid

# return whether the attack was successful or not
true
end

# Number of successful attacks made by the “opponent” on this player GameBoard
def num_successful_attacks
0
end

# returns Boolean
# returns True if all the ships are sunk.
# Return false if at least one ship hasn’t sunk.
def all_sunk?
true
end

# String representation of GameBoard (optional but recommended)
def to_s
“STRING METHOD IS NOT IMPLEMENTED”
end
end

CS计算机代考程序代写 open P3.Nfa

open P3.Nfa
open P3.Regexp

let string_of_int_list lst =
“[” ^ String.concat “;” (List.map string_of_int lst) ^ “]”

let string_of_int_list_list lst =
“[” ^ String.concat “;” (List.map string_of_int_list lst) ^ “]”

let init_str =
“digraph G {
rankdir=LR; ”
^ string_of_int (Hashtbl.hash “-1″)
^ ” [style=”invis”];

let end_str = “
}”

let nodup x lst = if List.mem x lst then lst else x :: lst

let string_of_vtx _ lst =
List.fold_left
(fun acc (v, f) ->
let shape = if f then “doublecircle” else “circle” in
acc
^ Printf.sprintf “%d [label=”%s”,shape=%s];
” (Hashtbl.hash v) v shape
)
“” lst

let string_of_ed _ lst =
List.fold_left
(fun acc ((s1, _), c, _, (s2, _)) ->
acc
^ Printf.sprintf “%d -> %d [label=”%s”];
” (Hashtbl.hash s1)
(Hashtbl.hash s2) c )
“” lst

let write_nfa_to_graphviz (show : ‘q -> string) (nfa : (‘q, char) nfa_t) : bool
=
let name = “output.viz” in
let ss, fs, ts = (nfa.q0, nfa.fs, nfa.delta) in
let sv = (show ss, List.mem ss fs) in
let vt, ed =
List.fold_left
(fun (vt, ed) (v1, c, v2) ->
let v1′ = (show v1, List.mem v1 fs) in
let v2′ = (show v2, List.mem v2 fs) in
let c’ = match c with None -> “ε” | Some x -> String.make 1 x in
let pair = List.mem (v2, c, v1) ts in
let e = (v1′, c’, pair, v2′) in
(nodup v2′ (nodup v1′ vt), nodup e ed) )
([], []) ts
in
let ed = ((“-1″, false), ” “, false, (show ss, List.mem ss fs)) :: ed in
let dot =
init_str ^ string_of_vtx show (sv :: vt) ^ string_of_ed show ed ^ end_str
in
let file = open_out_bin name in
output_string file dot ;
flush file ;
Sys.command (Printf.sprintf “dot %s -Tpng -o output.png && rm %s” name name)
= 0

;;
print_string “Type regexp to visualize: ”

let line = read_line ()

;;
print_string “Convert to DFA (y/n)? ”

let line2 = read_line ()

let nfa = string_to_nfa line

;;
if line2 = “n” then
if write_nfa_to_graphviz string_of_int nfa then
print_string “Success! Open ‘output.png’ to see your visualized NFA.

else
print_string
“Failure! Are you sure you have graphviz installed on your machine?

else if write_nfa_to_graphviz string_of_int_list (nfa_to_dfa nfa) then
print_string “Success! Open ‘output.png’ to see your visualized DFA.

else
print_string
“Failure! Are you sure you have graphviz installed on your machine?