Facebook
From Wet Butterfly, 7 Years ago, written in Scala.
This paste is a reply to Untitled from Idiotic Cat - go back
Embed
Viewing differences between Untitled and Re: Untitled
object Main {
  val 
let xs = 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: Nil
  
  def nTy[A](xs: List[A], n: Int):A 
[];;

let rec nTy 
{
    val h::t = xs
    
function (xs, n) match {
      case(Nil, _) => throw new Exception("Error")
      case(_, 
->
        if (xs = []) then raise (Failure "Error")
        else if (n = 
1) => h
      case(_, _) => nTy(t, 
then List.hd xs
        else nTy(List.tl xs, 
n - 1)
    }
  }
  
1);;
nTy(xs, 3)
  
  def podzielPoN[A](a: List[A], n: Int): List[List[A]] 
2);;


let rec podzielPoN 
{
    
    def podzielPoN_tr[A](a: List[A], n: Int, b: List[A]): List[List[A]] 
function (xs, n) ->
        
        let rec podzielPoN_it 
{
      if(n==0) List(b, a)
      
function (a, b, n) ->
                if (n = 0) then (b, a)
                
else podzielPoN_tr(a.tail, podzielPoN_it(List.tl a, b @ (List.hd a :: []), n - 1, b ++ List(a.head))
    }
    
    podzielPoN_tr(a,n, List[A]())
  }
  podzielPoN(xs, 2)
  
  def podzielWgMod[A](list: List[Int], n: Int): List[List[Int]] 
1)
        in podzielPoN_it(xs, [], n);;
podzielPoN (xs, 2)


let rec podzielWgMod 
{
    
    def podzielWgMod_tr(xs: List[Int], a: List[Int], b: List[Int]): List[List[Int]] 
function (xs, n) ->
        
        let rec podzielWgMod_it 
{
      
function (xs, a, b) ->
                
if (xs == Nil) List(a, b)
      
= []) then (a, b)
                
else if (xs.head % (List.hd xs mod == 0) podzielWgMod_tr(xs.tail, then podzielWgMod_it(List.tl xs, ++ List(xs.head), b)
      
@ (List.hd xs :: []), b)
                
else podzielWgMod_tr(xs.tail, podzielWgMod_it(List.tl xs, a, b ++ List(xs.head))
    }
    podzielWgMod_tr(list, List(), List())
  }
  
@ (List.hd xs :: []))
        in podzielWgMod_it(xs, [], []);;
podzielWgMod(xs, 2)
  
  def coNTy[A](xs: List[A], n: Int): List[A] 
2);;


let rec coNTy 
{
    
    def coNTy_it[A](x: List[A], i: Int): List[A] 
function (xs, n) ->
        
        let rec coNTy_it 
{
      
function (x, i) ->
                
if (x == Nil) Nil
      
= []) then []
                
else if (i == 1) x.head then List.hd x :: coNTy_it(x.tail, n)
      
coNTy_it(List.tl x, n)
                
else coNTy_it(x.tail, coNTy_it(List.tl x, i - 1)
    }
    
1)
        in 
coNTy_it(xs, n)
  }
  
n);;
coNTy(xs, 3)
}
2);;

Replies to Re: Untitled rss

Title Name Language When
Re: Re: Untitled Denim Porcupine ocaml 7 Years ago.