I have this code here.
map<int, int[2]> m;
map m is initialized as such. The following code attempts to add a new value for a key.
while(scanf("%d %d %d %c", &a,&b,&c,&d) == 1){
map<int, int[2]>::iterator it = m.find(a);
if(!(it == m.end())){
//found
if(d == 'C') { (it->second)[0]+=1; (it->second)[1] += c;}
if(d == 'I') { (it->second)[1] += 20;}
} else {
//not found
if(d == 'C') {int arr[2] = {1, c}; m[a] = arr;}
if(d == 'I') {int arr[2] = {0, 20}; m[a] = arr;}
}
}
However, m[a] = arr; gives me the following error: expression must be a modifiable lvalue.
What does this mean?
Built-in arrays are not assignable, and are generally best avoided in modern C++. Use std::array<int, 2> instead, which is copyable just fine:
map<int, std::array<int, 2>> m;
while(scanf("%d %d %d %c", &a,&b,&c,&d) == 1){
auto it = m.find(a);
if(!(it == m.end())){
//found
if(d == 'C') { (it->second)[0]+=1; (it->second)[1] += c;}
if(d == 'I') { (it->second)[1] += 20;}
} else {
//not found
if(d == 'C') {std::array<int, 2> arr = {1, c}; m[a] = arr;}
if(d == 'I') {std::array<int, 2> arr = {0, 20}; m[a] = arr;}
}
}
int[2] is not suitable for being the value, the mapped type, of a std::map since you can't assign on object of that type to another object of that type.
int a[2];
int b[2];
b = a; // Not allowed.
You may use std::array<int, 2> as a good substitute.
map<int, std::array<int, 2>> m;
That is because you can't simply copy c-style arrays using assignment.
You could wrap your array in a structure, which will copy OK, or use std::array<int,2> as your type.
Another option is to just use a std::pair<int, int> as the value:
map<int, std::pair<int, int>> m;
while(scanf("%d %d %d %c", &a,&b,&c,&d) == 1){
auto it = m.find(a);
if(!(it == m.end())){
//found
if(d == 'C') { (it->second).first +=1; (it->second).second += c;}
if(d == 'I') { (it->second).second += 20;}
} else {
//not found
if(d == 'C') {m[a] = {1, c};}
if(d == 'I') {m[a] = {0, 20};}
}
}
Related
Node * create(Node * root, int I, int J, string str)
{
if (I == J) { root -> data =str[I]; root -> left=NULL; root -> right=NULL; }
int i = 0, j = 0, k = 0, l = 0;
//// to store the data of root
string val;
for (i = I; i < J; i++) {
if (str[i] == '(') break;
val.push_back(str[i]);
}
root -> data = stoi(val);
stack < char > st;
for (j = i; j < J; j++) {
if (str[j] == '(') st.push(str[j]);
else if (str[j] == ')') st.pop();
if (st.empty()) break;
}
for (l = j + 1; l < J; l++) {
if (str[l] == '(') st.push(str[l]);
else if (str[l] == ')') st.pop();
if (st.empty()) break;
}
k = j + 1;
if (j - i == 2) root -> left -> data = str[i + 1];
else
root -> left = create(root -> left, i + 1, j - 1, str);
if (l == k) root -> right=NULL;
else if (l - k == 2) root -> right -> data = str[k + 1];
else
root -> right = create(root -> right, k + 1, l - 1, str);
return root;
}
Node * treeFromString(string str){
Node * p = create(p, 0, str.size() - 1, str);
return p;
}
Here I have initialized variables i , j , k , l to track the left child and right child bracket in the string. I , J are the range of the node for a particular activation record of recursion.
I assume you parsed some expression, by your code I pre-implemented it.
I just implement build a tree for following expression:
expression: |<symbol>| <integer> '(' <expression> ')' '('<expression>')'
symbol : any C++ `char` single byte character.
integer : any C++ valid int type value.
#include <iostream>
#include <string>
#include <string_view> // C++17 std::string_view
#include <charconv> // C++17 std::from_chars.
#include <cassert>
//simulate Node class
struct Node
{
Node *left, *right;
int data;
};
//1. use string_view instead of triple I, J, std::string.
//2. First argument Node* root - needn't. It should be local variable.
Node * create(std::string_view str)
{
assert(!str.empty());
if (str.size() == 1)
{
Node* root = new Node; //-> YOU should allocate a memory for root.
root -> data =str[0];
root -> left=nullptr; // use nullptr instead of NULL for c++11 or later.
root -> right=nullptr;
return root; // exit needed!
}
Node* root = new Node;
root->left = nullptr;
root->right = nullptr;
root->data = 0;
//// to store the data of root
//2. THERE NEED take an integer until first '(' symbol.
{
std::size_t i = 0;
while (i < str.size() && str[i] != '(' )
++i;
// str[0 .. i) - interval is an integer.
int val = 0;
(void)std::from_chars(str.data(), str.data() + i, val); // FOR simplifity don't check validness of conversation.
str.remove_prefix(i);
root->data = val;
}
//3. SKIP balanced '(' and ')'
/*stack < char > st;
for (j = i; j < J; j++) {
if (str[j] == '(') st.push(str[j]);
else if (str[j] == ')') st.pop();
if (st.empty()) break;
}
* */
/** we can implement it another way */
assert(!str.empty() && str[0] == '(' );
std::string_view within_bracket;
{
int balanced_brackets = 0;
std::size_t i = 0;
while (i < str.size())
{
if (str[i] == '(') ++ balanced_brackets;
else if (str[i] == ')' ) --balanced_brackets;
i++;
if (balanced_brackets == 0)
break;
}
assert (i > 0 && str[ i - 1 ] == ')' );
// 0 1 2 3
// str[0..i) - is '(' ... ')' symbols.
within_bracket = std::string_view(str.data() + 1, i - 2);
str.remove_prefix(i);
}
/****4. THIS second balanced bracket check */
std::string_view second_within_bracket;
/*
for (l = j + 1; l < J; l++) {
if (str[l] == '(') st.push(str[l]);
else if (str[l] == ')') st.pop();
if (st.empty()) break;
}
k = j + 1;
*/
assert(!str.empty() && str[0] == '(' );
// ========== second balanced brackets check ==========
{
std::size_t i = 0;
int balanced_brackets = 0;
while (i < str.size())
{
if (str[i] == '(') ++ balanced_brackets;
else if (str[i] == ')' ) --balanced_brackets;
i++;
if (balanced_brackets == 0)
break;
}
// 0 1 2 3
// str[0..i) - is '(' ... ')' symbols.
second_within_bracket = std::string_view(str.data() + 1, i - 2);
str.remove_prefix(i);
}
//================================
/*
if (j - i == 2) root -> left -> data = str[i + 1];
else
root -> left = create(i + 1, j - 1, str);
if (l == k) root -> right=NULL;
else if (l - k == 2) root -> right -> data = str[k + 1];
else
root -> right = create(root -> right, k + 1, l - 1, str);
*/
root->left = create(within_bracket);
root->right = create(second_within_bracket);
return root;
}
Node * treeFromString(std::string_view str){
Node * p = create(str);
return p;
}
void printTree(Node* root, int level = 0)
{
if (root==nullptr) return;
for (int i= 0; i < level; ++i) std::cout << "--";
std::cout << " data = " << root->data << std::endl;
printTree(root->left, level + 1);
printTree(root->right, level + 1);
}
int main(){
std::string str = "12(8(7)(5))(9(3)(2(1)(8)))";
Node * expr = treeFromString(str);
printTree(expr);
}
godbold output:
Program returned: 0
data = 12
-- data = 8
---- data = 55
---- data = 53
-- data = 9
---- data = 51
---- data = 2
------ data = 49
------ data = 56
This answer is a bit different, it assumes you are loading a tree of integer values from a string, that could be loaded from a file. Next time you ask a question about code, could you please explain a little bit what the code does? Guessing does take some time and some effort.
I've reused the main() and PrintTree() functions from Khurshid Normuradov's answer. I hope he won't mind.
I took the liberty to add modern c++ coding techniques because this question is tagged c++17, so you're getting an example in c++17.
#include <algorithm>
#include <iostream>
#include <memory>
#include <string>
#include <string_view>
struct Node {
std::unique_ptr<Node> left = nullptr;
std::unique_ptr<Node> right = nullptr;
int value = 0;
};
std::unique_ptr<Node> treeFromString(std::string_view str) {
std::cout << "treeFromString(\"" << str << "\")\n";
if (str.empty()) return {};
auto node = std::make_unique<Node>();
// extract an int
auto pos = str.find_first_not_of("0123456789");
auto val = str.substr(0, pos);
// optional: std::stoi() would throw anyway in this case
if (val.empty())
throw std::runtime_error("invalid value in expression");
node->value = std::stoi(std::string{val});
if (val.length() == str.length()) return node;
str = str.substr(val.length());
// Both left/right parsing are similar and use this
// common subroutine.
// expects parens delimited string as input.
// param str in: str string to parse from
// out: whatever's left to parse
// returns string content within parens, parens not included.
auto extract_parens_contents = [](std::string_view& str) {
// right here would be the perfect place to insert code to skip
// whitespace if you ever needed to do that.
// find parens extent
int parens = 0;
auto parens_end =
std::find_if(str.begin(), str.end(), [&parens](char c) {
parens += (c == '(') - (c == ')');
return (parens == 0);
});
if (parens_end == str.end())
throw std::runtime_error("unbalanced parens in expression");
// extract result
auto result = std::string_view(
str.begin() + 1, std::distance(str.begin() + 1, parens_end));
// remove spent bytes from input stream
str = std::string_view(
parens_end + 1,
str.length() - std::distance(str.begin(), parens_end + 1));
return result;
};
node->left = treeFromString(extract_parens_contents(str));
node->right = treeFromString(extract_parens_contents(str));
return node;
}
// special thanks to user Khurshid Normuradov, who originally wrote the two functions below.
// it would be difficult to writing something that would be any better for the
// intended purpose.
void printTree(Node* root, int level = 0) {
if (root == nullptr) return;
for (int i = 0; i < level; ++i) std::cout << "--";
std::cout << " data = " << root->value << std::endl;
printTree(root->left.get(), level + 1);
printTree(root->right.get(), level + 1);
}
int main() {
std::string str = "12(8(7)(5))(9(3)(2(1)(8)))";
auto expr = treeFromString(str);
printTree(expr.get());
}
You can play with the code here: https://godbolt.org/z/ch3zv5KTT
please if there is any specific algorithm for implementing the divide operator as a function, guide me about their name. I want to implement a function that takes two floating number and return the result of the divide, but in implementation, I won't use "/".
I have done this in a much simpler version when we want just the q in integer,
function divide(num0, num1) {
if ("bigint" != typeof num0 || "bigint" != typeof num1) {
throw new TypeError("The arguments should be bigint.");
}
if (num1 > num0) {
return 0;
}
for (var i = 0n; num0 >= num1; i++) {
num0 -= num1;
}
return i;
}
"I use bigint numeric type just two restrict to integer"
but I think this approach couldn't extend two return floating results. my guess is I approach binary level operation or so; thanks if learning me about any flowchart, pseudo-code, or code-snippet "in any language" to deal with this problem
I wrote this one for this question in js:
function justIntegerDivide(num0, num1) {
for (var q = 0; num0 >= num1; q++) {
num0 -= num1;
}
return [q, num0];
}
const divide = (n0, n1, afterPoint = 10) => {
if ((0 == n1 || 0n == n1) && 0 < n0) return Infinity;
if ((0 == n1 || 0n == n1) && 0 > n0) return -Infinity;
if ((0 == n1 || 0n == n1) && 0 == n0) return NaN;
if ("number" == typeof n0 && "number" == typeof n1) {
let sign = Math.sign(n0) * Math.sign(n1);
let num0 = Math.abs(n0),
num1 = Math.abs(n1);
let counter = 0;
let [q, r] = justIntegerDivide(num0, num1);
result = `${q}.`;
for (counter = 1; counter < afterPoint; counter++) {
var newReminder;
let qAfter;
previousReminder = 1 == counter ? r : newReminder;
[qAfter, newReminder] = justIntegerDivide(previousReminder * 10, num1);
result += qAfter;
if (0 == newReminder) {
return +result * sign;
}
}
return +result * sign;
} else if ("bigint" == typeof n0 && "bigint" == typeof n1) {
let sign = (n0 > 0 && n1 > 0) || (n0 < 0 && n1 < 0) ? 1n : -1n;
let num0 = n0 > 0 ? n0 : -n0;
let num1 = n1 > 0 ? n1 : -n1;
if (num0 < num1) {
return 0n;
}
for (var i = 0n; num0 >= num1; i++) {
num0 -= num1;
}
return i * sign;
} else {
throw new TypeError("Both arguments should be number or bigint");
}
};
I'm trying to solve this question: http://www.spoj.com/problems/ALLIZWEL/
Find whether there is a path in the given matrix which makes the
sentence “ALL IZZ WELL”.
There is a path from any cell to all its neighbouring cells.
A neighbour may share an edge or a corner.
Input Specification:
The first line consists of an integer t representing the number of test cases.
The first line of each test
case consists of two integers R and C representing the number of rows and number of columns in the matrix.
Output Specification:
For each test case print “YES” if there is a path which makes the sentence “ALLIZZWELL”.
Else print “NO”.
For sample test cases, open the link.
My code:
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <climits>
#include <set>
using namespace std;
char matrix[101][101];
bool var;
int r,c;
bool check (string str,int pos, bool visited[101][101],int i, int j);
int main (void)
{
int t,i,j;
cin>>t;
bool ans;
while (t != 0)
{
int r,c,flag=0;
cin>>r>>c;
for ( i = 0; i < r; i++ )
{
for ( j = 0; j < c; j++ )
{
cin>>matrix[i][j];
}
}
string str = "ALLIZZWELL";
int pos = 1;
for ( i = 0; i < r; i++ )
{
for ( j = 0; j < c; j++ )
{
bool visited[101][101];
for ( i = 0; i < 101; i++ )
for ( j = 0; j < 101; j++ )
visited[i][j] = false;
visited[i][j] = true;
if (matrix[i][j] == 'A') // for all possible starting positions
ans = check(str,pos,visited,i,j);
if (ans == true)
{
cout<<"YES\n";
flag = 1;
break;
}
if (flag == 1)
break;
}
}
if (flag == 0)
cout<<"NO\n";
t--;
}
return 0;
}
bool check (string str,int pos, bool visited[101][101],int i, int j) // checking for all possible test cases
{
bool result = false;
if (pos == str.length() + 1)
return true;
if (i+1 < r && visited[i+1][j] != true && matrix[i+1][j] == str[pos])
{
visited[i+1][j] = true;
result = result || check(str,pos+1,visited,i+1,j);
if (result == false)
visited[i+1][j] = false;
}
else if (i-1 >= 0 && visited[i-1][j] != true && matrix[i-1][j] == str[pos])
{
visited[i-1][j] = true;
result = result || check(str,pos+1,visited,i-1,j);
if (result == false)
visited[i-1][j] = true;
}
else if (j+1 < c && visited[i][j+1] != true && matrix[i][j+1] == str[pos])
{
visited[i][j+1] = true;
result = result || check(str,pos+1,visited,i,j+1);
if (result == false)
visited[i][j+1] = true;
}
else if (j-1 >= 0 && visited[i][j-1] != true && matrix[i][j-1] == str[pos])
{
visited[i][j-1] = true;
result = result || check(str,pos+1,visited,i,j-1);
if (result == false)
visited[i][j-1] = true;
}
else if (i+1 < r && j+1 < c && visited[i+1][j+1] != true && matrix[i+1][j+1] == str[pos])
{
visited[i+1][j+1] = true;
result = result || check(str,pos+1,visited,i+1,j+1);
if (result == false)
visited[i+1][j+1] = true;
}
else if (i+1 < r && j-1 >= 0 && visited[i+1][j-1] != true && matrix[i+1][j-1] == str[pos])
{
visited[i+1][j-1] = true;
result = result || check(str,pos+1,visited,i+1,j-1);
if (result == false)
visited[i+1][j-1] = true;
}
else if (i-1 >= 0 && j+1 < c && visited[i-1][j+1] != true && matrix[i-1][j+1] == str[pos])
{
visited[i-1][j+1] = true;
result = result || check(str,pos+1,visited,i-1,j+1);
if (result == false)
visited[i-1][j+1] = true;
}
else if (i-1 >= 0 && j-1 >= 0 && visited[i-1][j-1]!= true && matrix[i-1][j-1] == str[pos])
{
visited[i-1][j-1] = true;
result = result || check(str,pos+1,visited,i-1,j-1);
if (result == false)
visited[i-1][j-1] = true;
}
return false;
}
The code is quite self-explanatory: I am trying all possible cases.
I am getting a WA in the third test case, i.e.
2 9
A.L.Z.E..
.L.I.W.L.
I tried debugging but I couldn't narrow down my problem.
The main problems are:
Using i and j in the loop clearing visited (as well as the outer loops)
Using r and c as global variables in check, but writing them as local variables in main
Always returning false from check (instead of result)
Only trying the first choice in check (turn "else if" into "if")
Not clearing the value in ans
Only breaking out of the inner loop, not both the i and j loop
Terminating the search when pos gets to str.length()+1 instead of str.length()
It often helps to put some print statements in recursive functions like these, try them out on a simple example, and see whether the sequence of calls matches your expectations.
I'm trying to construct an algorithm that runs at O(nb) time with the following input/question:
input: an array A[1..n] of n different integers and an integer b (i am assuming that the numbers in A are sequential, starting at 1 ending at n, i.e. for n=4 A[1,2,3,4].
question: in how many ways can b be written as the sum of elements of the array when elements in A[] can only be used once?
I've kind of hit a wall on this one. I'm looking for some kind of recursive solution, but I don't see how to avoid using repeat numbers. Like, for instance, if we started at 1 and stored all the ways to make one (just 1) then 2 (just 2) then three (3 or 2+1) etc, it shouldn't be hard to see how many ways we can make larger numbers. But if, for instance, we take 5, we will see that it can be broken into 4+1, and 4 can be further broken down into 3+1, so then we would see 2 solutions (4+1, and 3+1+1), but one of those has a repeat of a number. Am I missing something obvious? Thanks so much!
Recursive and dynamic solutions in C:
#include <stddef.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
typedef unsigned char uchar;
typedef unsigned int uint;
typedef struct tAddend
{
struct tAddend* pPrev;
uint Value;
} tAddend;
void findRecursiveSolution(uint n, uint maxAddend, tAddend* pPrevAddend)
{
uint i;
for (i = maxAddend; ; i--)
{
if (n == 0)
{
while (pPrevAddend != NULL)
{
printf("+%u", pPrevAddend->Value);
pPrevAddend = pPrevAddend->pPrev;
}
printf("\n");
return;
}
if (n >= i && i > 0)
{
tAddend a;
a.pPrev = pPrevAddend;
a.Value = i;
findRecursiveSolution(n - i, i - 1, &a);
}
if (i <= 1)
{
break;
}
}
}
void printDynamicSolution(uchar** pTable, uint n, uint idx, uint sum, tAddend* pPrevAddend)
{
uchar el = pTable[idx][sum];
assert((el != 0) && (el != 5) && (el != 7));
if (el & 2) // 2,3,6 - other(s)
{
printDynamicSolution(pTable,
n,
idx - 1,
sum,
pPrevAddend);
}
if (el & 4) // self + other(s)
{
tAddend a;
a.pPrev = pPrevAddend;
a.Value = idx + 1;
printDynamicSolution(pTable,
n,
idx - 1,
sum - (idx + 1),
&a);
}
if (el & 1) // self, found a solution
{
tAddend a;
a.pPrev = pPrevAddend;
a.Value = idx + 1;
pPrevAddend = &a;
while (pPrevAddend != NULL)
{
printf("+%u", pPrevAddend->Value);
pPrevAddend = pPrevAddend->pPrev;
}
printf("\n");
}
}
void findDynamicSolution(uint n)
{
uchar** table;
uint i, j;
if (n == 0)
{
return;
}
// Allocate the DP table
table = malloc(sizeof(uchar*) * n);
if (table == NULL)
{
printf("not enough memory\n");
return;
}
for (i = 0; i < n; i++)
{
table[i] = malloc(n + 1);
if (table[i] == NULL)
{
while (i > 0)
{
free(table[--i]);
}
free(table);
printf("not enough memory\n");
return;
}
}
// Fill in the DP table
for (i = 0; i < n; i++)
{
for (j = 0; j <= n; j++)
{
if (i == 0)
{
table[i][j] = (i + 1 == j); // self
}
else
{
table[i][j] = (i + 1 == j) + // self
2 * (table[i - 1][j] != 0) + // other(s)
4 * ((j >= i + 1) && (table[i - 1][j - (i + 1)] != 0)); // self + other(s)
}
}
}
printDynamicSolution(table, n, n - 1, n, NULL);
for (i = 0; i < n; i++)
{
free(table[i]);
}
free(table);
}
int main(int argc, char** argv)
{
uint n;
if (argc != 2 || sscanf(argv[1], "%u", &n) != 1)
{
n = 10;
}
printf("Recursive Solution:\n");
findRecursiveSolution(n, n, NULL);
printf("\nDynamic Solution:\n");
findDynamicSolution(n);
return 0;
}
Output:
for 10:
Recursive Solution:
+10
+1+9
+2+8
+3+7
+1+2+7
+4+6
+1+3+6
+1+4+5
+2+3+5
+1+2+3+4
Dynamic Solution:
+1+2+3+4
+2+3+5
+1+4+5
+1+3+6
+4+6
+1+2+7
+3+7
+2+8
+1+9
+10
See also on ideone.
Let F(x,i) be the number of ways elements of A[1:i] can be summed to get x.
F(x,i+1) = F(x-A[i+1],i) + F(x,i)
That is it!
This is not a dynamic programming solution though. Non-recursive.
Assumption that arr is sorted in your case like [i....j] where a[i] <= a[j]
That's easy enough
void summer(int[] arr, int n , int b)
{
int lowerbound = 0;
int upperbound = n-1;
while (lowerbound < upperbound)
{
if(arr[lowerbound]+arr[upperbound] == b)
{
// print arr[lowerbound] and arr[upperbound]
lowerbound++; upperbound--;
}
else if(arr[lowerbound]+arr[upperbound] < b)
lowerbound++;
else
upperbound--;
}
}
The above program is easily modifiable to a recursive you need to only change the function definition by passing lowerbound and upperbound.
Case for termination is still lowerbound < upperbound
Base case is if arr[lowerbound] +arr[upperbound] == b
Edited based on comments
You will need to use a modified version of integer knapsack problem. The values of [i,j] both need to be modified accordingly. You are having the problem because you are not most probably modifying your i carefully, Increase your i accordingly then their will not be repetition like the one you are having.
I'm trying to get the in-place radix sort example from In-Place Radix Sort working. So far I have this:
import std.random;
void swap(ref string i,ref string j) {
string tmp = i;
i = j;
j = tmp;
}
void radixSort(ref string[] seqs, size_t base = 0) {
if(seqs.length == 0)
return;
size_t TPos = seqs.length, APos = 0;
size_t i = 0;
while(i < TPos) {
if(seqs[i][base] == 'A') {
swap(seqs[i], seqs[APos++]);
i++;
}
else if(seqs[i][base] == 'T') {
swap(seqs[i], seqs[--TPos]);
} else i++;
}
i = APos;
size_t CPos = APos;
while(i < TPos) {
if(seqs[i][base] == 'C') {
swap(seqs[i], seqs[CPos++]);
}
i++;
}
if(base < seqs[0].length - 1) {
radixSort(seqs[0..APos], base + 1);
radixSort(seqs[APos..CPos], base + 1);
radixSort(seqs[CPos..TPos], base + 1);
radixSort(seqs[TPos..seqs.length], base + 1);
}
}
void main(string[] args) {
string [] sequences;
for(int n=0;n<10;n++) {
string seq;
for(int i=0;i<10;i++) {
int r = rand()%4;
if(r == 0) seq = seq ~ "A";
if(r == 1) seq = seq ~ "C";
if(r == 2) seq = seq ~ "G";
if(r == 3) seq = seq ~ "T";
}
sequences = sequences ~ seq;
}
writefln("Unsorted");
for(size_t n=0;n<10;n++) {
writefln(sequences[n]);
}
radixSort(sequences,0);
writefln("Sorted");
for(size_t n=0;n<10;n++) {
writefln(sequences[n]);
}
}
However, this fails with:
radix.d(36): Error: slice expression seqs[0u..APos] is not a modifiable lvalue
radix.d(37): Error: slice expression seqs[APos..CPos] is not a modifiable lvalue
radix.d(38): Error: slice expression seqs[CPos..TPos] is not a modifiable lvalue
radix.d(39): Error: slice expression seqs[TPos..seqs.length] is not a modifiable lvalue
Under the Digital Mars D Compiler v1.066. I guess slices are not mutable, but... how should I go about fixing this?
I'm new to D and largely just interested in getting this example working.
You only need ref if you want to modify the reference itself. For an array, that means changing the length or reallocating. Since your radix sort is in-place, I'm not sure why you'd want that.
I have an implementation that's pretty complete at https://github.com/nordlow/phobos-next/blob/master/src/nxt/integer_sorting.d#L38.
Feel free to borrow whatever you need.