Questions tagged [rosetta-code]

Rosetta Code is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in learning another.

12 questions
4
votes
1 answer

Implementing Hofstadter-Conway algorithm without raw recursion

I was playing around with trying the complete the Hofstadter-Conway $10,000 sequence task in Scala on Rosetta Code. I want to use as idiomatic Scala as possible, but I'm having trouble implementing the algorithm without using raw recursion, which…
Garrett Rowe
  • 1,205
  • 9
  • 13
4
votes
4 answers

Levenshtein distance in Swift3

I'm using a tutorial from Rosetta Code to calculate Levenshtein distance. It seems their code is in Swift2 so I get this error Binary operator '+' cannot be applied to operands of type '[Int]' and 'Repeated' when doing this:…
Jerry U
  • 618
  • 9
  • 22
2
votes
1 answer

Equilibrium Index - What's wrong with my solution?

I have taken this example test before I'll try to take the real one for a job interview. The challenge is to implement the Equilibrium Index problem correctly. I have coded some sort of solution that works only for the simple example and some of the…
the_drow
  • 18,571
  • 25
  • 126
  • 193
2
votes
3 answers

How can built-in sorting algorithm be so fast?

Quicksort is said to be one of the most quick algorithms for sorting data inside a list/table/whatever. Anyway how comes the rosettacode Lua implementation of this algorithm function quicksort(t) if #t < 2 then return t end local pivot =…
user6245072
  • 2,051
  • 21
  • 34
2
votes
3 answers

FFT using recursive python function

I am trying to use the following code for finding FFT of a given list. After a lot of trials I have found that this code runs only for an input list having 2^m or 2^m+1 elements. Can you please clarify why this is so and whether it can be modified…
1
vote
1 answer

f#: Strange syntax in example using ".. in let .."

I am reading through an example on RosettaCode and do not exactly know what the following line is doing. let min,subheap = findMin heap' in let rtn = root topnode It seems that findMin heap' is self contained unit of execution. I do not know how…
Phillip Scott Givens
  • 5,256
  • 4
  • 32
  • 54
0
votes
2 answers

Is this a valid Javascript solution for Rosetta Code: Balanced Brackets?

Description of the problem: https://rosettacode.org/wiki/Balanced_brackets For some reason, Freecodecamp thinks my solution isn't valid to include in their directory, I just want some confirmation…
0
votes
2 answers

Why is my code outputting only "opened" and not "closed"?

This is a 100 doors Rosseta code challenge. I have been trying to figure out why the output is all "opened". I don't understand why, since when I go through the loop, it makes sense logically. function getFinalOpenedDoors(numDoors) { // Good…
Evank800
  • 17
  • 3
0
votes
1 answer

SQL `SELECT 'some string value' AS fieldname` equivalent in Powershell?

In SQL I can go SELECT actualField, "repeat" AS bs_repeated_value FROM Table1 And I can repeat the bs_repeated_value field as many times as there are rows no matter what I name the field! Now in a similar and like manner in Powershell I…
leeand00
  • 25,510
  • 39
  • 140
  • 297
0
votes
1 answer

Execute Prolog program with output apart from true/false

I am trying to execute the example code from RosettaCode's take on writing an evolutionary algorithm in Prolog (see here). Can anybody tell me how to generate the same output as displayed below the code example?
0
votes
4 answers

Ruby 100 doors returning 100 nil

I'm solving the '100 doors' problem from Rosetta Code in Ruby. Briefly, there are 100 doors, all closed, designated 1 to 100 100 passes are made, designated 1 to 100 on the ith pass, every ith door is "toggled": opened if it's closed, closed if…
Dex F
  • 1
0
votes
1 answer

Trying to implement Huffman Encoding in C# - Is it correct?

I'm trying to implement a Huffman encoding in Visual Studio using C# as programming language. I have found an example on rosettacode.org: http://rosettacode.org/wiki/Huffman_coding#C.23 but I'm not sure if this is a correct implementation. The…
Michael Andorfer
  • 1,660
  • 5
  • 25
  • 45