there's no recursion in assembly recursion is a higher level construct
Nathan Hughes
shhhhhhhhhh
Adrian Carter
>there's no recursion in assembly what is call
Cooper Torres
function getmin(x, first=1, last=length(x)) if first>last nothing elseif first==last x[first] else min(x[first], getmin(x, first+1, last)) end end
Superior due to not copying the array so at least it's not an O(n^2) algorithm. Not superior due to not being tail call and no tail call optimization in Julia anyway.
Lincoln Wilson
sorry, you're right, there's call enjoy your stack overflow then, since there's no way to do tail optimization in assembly
Brody Walker
>write it in assembly if you want to challenge yourself in your favorite language! I'm not sure if you quite grasp the difference in your logic and his but I hope that making all the context of your post explicit helps you see it. If not then may whatever you believe in have mercy on your soul.
Colton Peterson
>stack overflow >in a language where you can simply subtract the stack pointer manually and optimise by hand
Ryder Cruz
>do something trivial in a language you already know >challenge yourself pick one
Xavier Morgan
He's just upset that someone dare corrects him and is lashing out by posing a more difficult challenge.
Adam Martin
damn, that's a lot like prolog min(A,[X|L]):- min(A,X,L). min(A,A, []). min(A, M, [X|L]):- M < X, min(A,M,L). min(A,M,[X|L]):- M > X, min(A,X,L).
Samuel Rivera
I think this works prolog:
``` min(X,Y, Y):-X=Y.
min_list([X], X). min_list([X|XS], Z):-min_list(XS, Y), min(X, Y, Z). ```
Asher Barnes
function sub(min, arrSize,array) { if(arrSize==0) return min; else { if(array[arrSize]
Xavier Thomas
POSIX compliance foo() { local a b this a="$1" b="$2" if [ -z "$a" -o -z "$b" ]; then return fi shift 2 if [ $a -eq $b -o $a -lt $b ]; then this=$a else this=$b fi if [ $# -eq 0 ]; then echo $this fi foo $this $* }
foo 9 5 4 5 3 2 7 6 3 7 6 9 8 3 8 4 2 5
Adrian Green
oops i meant arrSize==-1, min could at first index
Austin Edwards
prolog is a very beautiful language.
Juan Walker
impressive for some reason i can never figure out how to program in bash
minimum' :: ord a => [a] -> a minimum' [] = error "Cannot get minimum of empty list" minimum' [x] = x minimum' (x:xs) = min x (mininum' xs)
Why limit myself to integers?
Jaxon Cox
>using min
Gabriel Robinson
Fixpoint min : (n1 n2 : nat) : nat := match (leb n1 n2) with | true => n1 | false => n2 end.
Fixpoint find_min : (l : list nat) (default : nat): nat := match l with | [] => default | h :: t => min(h (find_min t default) end.
Hudson Hernandez
nevermind, i guess it's part of the ord typeclass?
Jordan Collins
It just compares two things and returns the lower but fine min' :: Ord a => a -> a -> a min' a b = if a > b then b else a
Daniel Sullivan
Love bash. It's like I'm an orchestrator for a symphony.
Adrian Watson
The biggest reason I left .NET. you've got a miniscule amount of code eating up so much screen space. I understand we have scroll wheels but holy fuck is that agonizing to look at.
Even when I used c# in highschool I still function { // }
Cameron Morgan
min(list) = reduce(x,y-> if (x= 1) first(list) else f(first(list),reduce(f,tail(list)) end
I would generally use higher order functions from the standard library instead of doing raw recursion though, since the latter tends to encourage big monolithic functions that are annoying to debug instead of single-expressions.
Juan Kelly
oops, condition in reduce should be length(list)
Blake White
Good points for using reduce. I dunno what lang that is but wouldn't if (length(list) >= 1) first(list) fail with an empty list? But yeah I get your point
Jack Rodriguez
Sure. Perl 6 has `min` routine too but I thought using it would defeat the purpose of the exercise.
Julian Wilson
I guess I am wondering how first(list) is defined in your lang for an empty list. In Racket and Scheme it's not allowed of course
Aaron Smith
that's javascript
Jonathan Martin
It would throw an exception due to empty list, which is the correct behaviour for the min function (i.e. using the version of reduce which takes no starting value and requires a nonempty list).
Jose Reyes
Alright. What lang is this?
Adam Williams
This might be better but your Haskell (?) implementation is still probably more general:
multi min(Num $a, Num $b) { $a < $b ?? $a !! $b } multi min(Str $a, Str $b) { $a lt $b ?? $a !! $b } multi find-minimum(@a where *.elems == 1) { @a.first } multi find-minimum(@a) { min(@a.first, find-minimum(@a.tail: *-1)); }
Alexander Reed
Point stands. Atrocious.
Ayden Brown
Well I'm the opposite, I can't stand that style you mention and I have to convert it to my style every time I copy some code. I just think it looks weird, the brackets being on the same x axis give better indication of code segments. But that's just like my opinion man.
is perl6 worth learning? i mean, there aren't any jobs in it..
Elijah Bailey
>another perl6 user on Jow Forums Finally there are two of us
Elijah Brooks
function minimum(list){ function findMin(list, i, min){ if(i === list.length){ return min; }else{ return findMin(list, i + 1, list[i] < min ? list[i] : min); } } return findMin(list, 0, list[0]); }
Isaac Scott
You know what gives a good indication of the code segments? Indenting it properly.
Lincoln Kelly
with iterators, won't allocate and will work on any type that can be somewhat compared fn min(list: &[T]) -> Option where T: PartialOrd { let mut it = list.iter(); it.next().map(|head| { it.fold(head, |cur, n| if cur.gt(n) { n } else { cur }) }) }
function minimum(list) return #list == 1 and list[1] or list[1] < minimum({table.unpack(list, 2, #list)}) and list[1] or minimum({table.unpack(list, 2, #list)}) end
Jaxon Martin
This isn't bash.
John James
proc min {list} { tailcall min+ $list 0 [lindex $list 0] } proc min+ {list lindex min} { if {$lindex == [llength $list]} { return $min } set min [expr {min($min,[lindex $list $lindex])}] tailcall min+ $list [incr lindex] $min }
Liam Gray
>still cares about POSIX compliance
That's a major league oof from where I'm standing fella
#!/usr/bin/fish
function minimum if test (count $argv) -eq 1 echo $argv[1] return end
set r (minimum $argv[2..-1])
if test $argv[1] -lt $r echo $argv[1] else echo $r end end
minimum 9 5 4 5 3 2 7 6 3 7 6 9 8 3 8 4 2 5
Michael Sanders
Here's Mercury, to Prolog as Haskell is to Scheme: :- pred min(int::out, list(int)::in) is nondet. min(X, [X]). min(if X
Henry Edwards
def find_min([head | tail], min \\ false) when head < min, do: find_min(tail, head) def find_min([head | tail], min), do: find_min(tail, min) def find_min([], min), do: min || raise("Empty list")
tfw haven't wrote elixir in like 2 months, feels weird having to re-think how flow works, my first one I just had a cond and then I refactored it.
Evan Cooper
from random import randint op = 0 faggot = randint(op, 8999) if op == faggot: print op else: cuck = list(range(op, faggot)) print cuck[op]
Blake Gomez
min(x,y)=x>y?x:y min(...a)=reduce(min, a)
Charles Ward
I'm still learning recursion with python def f(L, length, current_index, current_minimum): if current_index == length-1: return current_minimum else: for i in range(length): if i < current_index: pass else: if L[i] < current_minimum: current_minimum = L[i] return f(L, length, i+1, current_minimum) else: return f(L, length, i+1, current_minimum) break
l = [1,8,6,4,7,-2,2,6,4,8] print(f(l, len(l), 0, l[0]))
This outputs -2, so I think it is correct
Owen Lewis
I wish assembly was taught in intro to programming more often. It would dispel the struggles people have when trying to fathom such concepts. Setting up a stack frame context and being able to see the actual mechanics that make it work beats the top down approach, especially in a debugger. My first experience with recursion was in assembly, so it didn't seem like magic to me unlike to other high level programmers. All of these problems new comers have with recursion, pointers and understanding virtual memory layout should be learned under assembly.
Luke Cook
This. Literally this
Colton Taylor
function min(iterable) { const it = iterable[Symbol.iterator](); return function step({ value, done }, min) { return done ? min : step(it.next(), min > value ? value : min); }(it.next(), Infinity); }
Brody Parker
English: Given a list of numbers L, an index I, and a current smallest number N: a) The number in the I-th position (I=1 -> 1st) is X. 1) If I is 0, return N. 3) If X
Noah Hernandez
int min(int *tab, int n) { if(n == 1) return tab[0]; else { int l = min(tab, n/2); int r = min(tab+n/2, n-n/2); return l < r ? l : r; } }
I used to do C stuff like this a lot in my high school years. Can't say it's any useful in my actual programming job but it's pretty fun nonetheless.
Elijah Diaz
def min(list: List[Int], minimum: Int = Int.MaxValue): Int = list match { case head :: tail => min(tail, if(head < minimum) head else minimum) case Nil => minimum }
Daniel Phillips
def l_min(xs): if len(xs) == 1: return xs[0] elif xs[0] < x = l_min(xs[1:]):: return xs[0] else: return x
Robert Perez
let f (x:xs) = if xs == [] then x else if x < min then x else min where min = f xs I haven't programmed in haskell since I dropped out of college