Trigger value in a other line - mirc

ON *:TEXT:*3rd*:*: {
ON *:TEXT:*->*:*: {
if ($nick == Nickname) {
%value = $mid($1-, $calc($pos($1-, 3rd, 1) + 14), $calc($pos($1-, Second, $pos($1-, Second, 0)) - $pos($1-, 3rd, 1) - 23))
}
}
if($nick == Nickname) {
msg $chan $mid($1-, $calc($pos($1-, ->, 1) + 6), $calc($pos($1-, <-, $pos($1-, <-, 0)) - $pos($1-, ->, 1) - 9))
msg $chan %value
}
}
Chatoutput goes like
Nickname: It's the 3rd candy
Nickname: It's the second candy
What i want to do is, if the text 3rd is in the sentence trigger ON *:TEXT:*->*:*: {
and make a %variable of the input of 3rd in %value with the text of 3rd and pass it to the other line.
If not 3rd is in the sentence do nothing.
I hope i'm clearly with what i want it to do hope someone can help me.

first, you cant trigger an event with another
you can mix both in one
an example
on $*:text:/3rd.*->(.+)<-/iS:#:{
if ($nick == Nickname) {
%value = $regml(1)
msg $chan %value
}
}
what this script does is
on $:text:/3rd.->(.+)<-/iS:#:{
will match if "3rd" is on text, and if it is, catches texts that are between -> and <-
/iS i - will match for upper and lower cases
S - will strip any color codes, including bold, italic, and underline
%value = $regml(1) will give to %value the match between -> and <-
if ($nick == Nickname) { will trigger only for an specific Nickname
msg $chan %value will send the match text between -> and <- to channel
if it is not what you're looking for, tell me

Related

I'm having trouble with the code where the budget variable wasn't deducting throughout the loop. It instead do nothing or sometimes add up

enter image description hereI'm making an inventory system code and I'm a bit stuck finding a solution to the substraction problem, when I choose "ADD" and entering the input the formula wasn't getting the accurate outcome. For example, if I input Paper001 then its quantity, the output is fine at first but when input another item, the deduction instead becoming addition or sometimes doesn't do anything.
I tried dividing the values in the dictionary in 3 conditions but it turns out even worse.
while True:
try:
bg = float(input("Enter your budget : "))
print("-----------------------------------------------------------")
print(" Item name Item code Item price(Per set) \n")
print("1.Bond Paper : Paper001 100 PHP\n2.Yellow Paper : Paper002 50 PHP\n3.Intermediate Paper : Paper003 20 PHP\n\n")
s = bg
except ValueError:
print("PRINT NUMBER AS A AMOUNT")
continue
else:
break
a ={"name":[], "quant":[], "price":[]}
# converting dictionary to list for further updation
b = list(a.values())
# variable na value of "name" from dictionary 'a'
na = b[0]
# variable qu value of "quant" from dictionary 'a'
qu = b[1]
# This loop terminates when user select 2.EXIT option when asked
# in try it will ask user for an option as an integer (1 or 2)
# if correct then proceed else continue asking options
while True:
try:
print("-----------------------------------------------------------")
ch = int(input("1.ADD\n2.STORAGE LIST\n3.Customer purchase\n4.EXIT\nEnter your choice : "))
except ValueError:
print("\nERROR: Choose only digits from the given option")
continue
else:
# check the budget is greater than zero and option selected
# by user is 1 i.e. to add an item
if ch == 1 and s>0:
p_list={'Paper001':100,'Paper002':50,'Paper003':20}
pn = input("Enter item code : ")
if pn in p_list.keys():
q = int(input("Enter quantity : "))
else:
print("-----------------------------------------------------------")
print("Code is invalid")
continue
#checks if item name is already in the list
if pn in na:
ind = na.index(pn)
# remove quantity from "quant" index of the product
qu.remove(qu[ind])
# new value will be added to the previous value of user's quantity
qu.insert(ind, q)
tpr = (q+q)*p_list[pn]
print(f" Total product price:",tpr)
s = bg-tpr
print("\namount left", s)
else:
# append value of in "name", "quantity", "price"
na.append(pn)
# as na = b[0] it will append all the value in the
# list eg: "name"🙁"rice"]
qu.append(q)
# after appending new value the sum in price
# as to be calculated
tpr = q*p_list[pn]
print("\nTotal product price:",tpr)
s = bg-tpr
if s==0:
print("No more budget left")
print("\nAmount left :", s)
elif s>0:
print("\nAmount left :", s)
else:
print("Insufficient budget. Cannot buy item.")
print("Please restart and re-enter your budget.")
break
elif ch ==2 :
print("\n\n\nStorage list")
print("Item name Stocks ")
for i in range(len(na)):
print(f"{na[i]} {qu[i]}")
continue
elif ch == 3:
print("-----------------------------------------------------------")
p_list={'Paper001':100,'Paper002':50,'Paper003':20}
print("\n\n\nStorage list")
print("Item name Stocks ")
for i in range(len(na)):
print(f"{na[i]} {qu[i]}")
co = input("\nEnter customer's order : ")
if co in p_list.keys():
q = int(input("Enter quantity : "))
sl = qu[i]-q
print("Item is sold!")
print("Stocks left :",sl)
if sl <=0:
print("Please add new items!")
else:
print("-----------------------------------------------------------")
print("Code is invalid")
continue
elif ch==4:
print("")
print("\nThank your for shopping with us!")
break
elif s==0:
print("NO BUDGET LEFT. UNABLE TO ADD ITEMS.")
else:
print("ERROR: Choose only the digits given from the option.")

How to truncate a comma-separated value string with remainder count

I'm trying to achieve string truncate with "& more..." when string is truncated. I have this in picture:
Exact code minus text, in image:
func formatString() -> String {
let combinedLength = 30
// This array will never be empty
let strings = ["Update my profile", "Delete me", "Approve these letters"]
// In most cases, during a loop (no order of strings)
//let strings = ["Update", "Delete", "Another long word"]
let rangeNum = strings.count > 1 ? 2 : 1
let firstN = strings[0..<rangeNum]
// A sum of first 2 or 1
let actualLength = firstN.compactMap { $0.count }.reduce(0, +)
switch actualLength {
case let x where x <= combinedLength:
// It's safe to display all
return strings.map{String($0)}.joined(separator: ", ")
default:
if rangeNum == 2 {
if actualLength <= combinedLength {
return strings.first! + ", " + strings[1] + ", & \(strings.count - 2) more..."
}
return strings.first! + ", & \(strings.count - 1) more..."
}
// There has to be at least one item in the array.
return strings.first!
}
}
While truncateMode looks like a match, it's missing the , & n more... where n is the remainder.
My code may not be perfect but was wondering how to refactor. I feel there's a bug in there somewhere. I've not taken into consideration for larger screens: iPad where I would want to display more comma-separated values, I only look for the max 2 then display "& n more" depending on the size of the array.
Is there a hidden modifier for this? I'm using XCode 13.4.1, targeting both iPhone and iPad.
Edit:
The title is incorrect. I want to convert an array of strings into a comma-separated value string that's truncated using the function I have.

Displaying multiple values in for statement in Swift

Hi I am new to programming. I apologize beforehand if this is a stupid question, but I'm learning about For loops. The below is an example code I understand. I know how to write a basic For loop that iterates through a single variable in each loop, but how do I use a For loop to display multiple values in one loop. Example:
let treeArray = ["Pine", "Oak", "Yew", "Maple", "Birch", "Myrtle"]
for tree in treeArray {
print(tree)
}
I want to be able to print three variables in one loop so the code would print
Pine Oak Yew on one line
Maple Birch Myrtle and on the next
Instead of
Pine
Oak
Yew
Maple
Birch
Myrtle
Thanks!
You could use .enumerated() to pair the index with the element and then print(_:terminator:) using index % 3 to select the appropriate terminator (newline "\n" or space " "):
let treeArray = ["Pine", "Oak", "Yew", "Maple", "Birch", "Myrtle"]
for (index, tree) in treeArray.enumerated() {
print(tree, terminator: index % 3 == 2 ? "\n" : " ")
}
Output:
Pine Oak Yew
Maple Birch Myrtle
The general case: printing n items per line
In general, for printing n items per line:
print(tree, terminator: index % n == n - 1 ? "\n" : " ")
or equivalently:
print(tree, terminator: (index + 1) % n == 0 ? "\n" : " ")
If you want the last item to always be followed by a newline, then add an addition check for that:
print(tree, terminator: index % n == n - 1 || index == treeArray.endIndex - 1 ? "\n" : " ")
Use an array to store trees and
joined(separator: String)
on array to stitch them together.
let treeArray = ["Pine", "Oak", "Yew", "Maple", "Birch", "Myrtle"]
var treeNames = [String]()
for (count, tree) in treeArray.enumerated() {
treeNames.append(tree)
if ((count + 1) % 3) == 0 {
let treeLine = treeNames.joined(separator: " ")
print(treeLine)
treeNames.removeAll()
}
}

Difficulty getting readLine() to work as desired on HackerRank

I'm attempting to submit the HackerRank Day 6 Challenge for 30 Days of Code.
I'm able to complete the task without issue in an Xcode Playground, however HackerRank's site says there is no output from my method. I encountered an issue yesterday due to browser flakiness, but cleaning caches, switching from Safari to Chrome, etc. don't seem to resolve the issue I'm encountering here. I think my problem lies in inputString.
Task
Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail).
Input Format
The first line contains an integer, (the number of test cases).
Each line of the subsequent lines contain a String, .
Constraints
1 <= T <= 10
2 <= length of S < 10,000
Output Format
For each String (where 0 <= j <= T-1), print S's even-indexed characters, followed by a space, followed by S's odd-indexed characters.
This is the code I'm submitting:
import Foundation
let inputString = readLine()!
func tweakString(string: String) {
// split string into an array of lines based on char set
var lineArray = string.components(separatedBy: .newlines)
// extract the number of test cases
let testCases = Int(lineArray[0])
// remove the first line containing the number of unit tests
lineArray.remove(at: 0)
/*
Satisfy constraints specified in the task
*/
guard lineArray.count >= 1 && lineArray.count <= 10 && testCases == lineArray.count else { return }
for line in lineArray {
switch line.characters.count {
// to match constraint specified in the task
case 2...10000:
let characterArray = Array(line.characters)
let evenCharacters = characterArray.enumerated().filter({$0.0 % 2 == 0}).map({$0.1})
let oddCharacters = characterArray.enumerated().filter({$0.0 % 2 == 1}).map({$0.1})
print(String(evenCharacters) + " " + String(oddCharacters))
default:
break
}
}
}
tweakString(string: inputString)
I think my issue lies the inputString. I'm taking it "as-is" and formatting it within my method. I've found solutions for Day 6, but I can't seem to find any current ones in Swift.
Thank you for reading. I welcome thoughts on how to get this thing to pass.
readLine() reads a single line from standard input, which
means that your inputString contains only the first line from
the input data. You have to call readLine() in a loop to get
the remaining input data.
So your program could look like this:
func tweakString(string: String) -> String {
// For a single input string, compute the output string according to the challenge rules ...
return result
}
let N = Int(readLine()!)! // Number of test cases
// For each test case:
for _ in 1...N {
let input = readLine()!
let output = tweakString(string: input)
print(output)
}
(The forced unwraps are acceptable here because the format of
the input data is documented in the challenge description.)
Hi Adrian you should call readLine()! every row . Here an example answer for that challenge;
import Foundation
func letsReview(str:String){
var evenCharacters = ""
var oddCharacters = ""
var index = 0
for char in str.characters{
if index % 2 == 0 {
evenCharacters += String(char)
}
else{
oddCharacters += String(char)
}
index += 1
}
print (evenCharacters + " " + oddCharacters)
}
let rowCount = Int(readLine()!)!
for _ in 0..<rowCount {
letsReview(str:String(readLine()!)!)
}

Trying to get Javascript to delete the end characters on a stored string further than the last character

So I'm reading characters into a string in Javascript. I want the user to be able to delete characters they have stored, much as one would do in word processing.
function Update() {
if (Input.GetKeyDown("return")) c+= "\n";
if (Input.GetKeyDown("tab")) c+= " ";
if (Input.GetKeyDown("backspace")) c = c.Substring(0, c.Length - 1);
if (Input.inputString.Length != 0)
{
c += Input.inputString;
guiText.text = c;
}
}
The issue I'm running into is that after hitting backspace once, it stops going further back- I can only delete one character. For example, were I to type "example", and then hit backspace twice, I would have "exampl", whereas I would want to have "examp".
I'd love some help on figuring out where I'm going wrong here :) Thanks!
Full code in your question would have been better, You are storing one character at a time right? Try
function Update() {
if (Input.GetKeyDown("return")) c+= "\n";
else if (Input.GetKeyDown("tab")) c+= " ";
else if (Input.GetKeyDown("backspace")) c = c.Substring(0, c.Length - 1);
else if (Input.inputString.Length != 0) c += Input.inputString;
guiText.text = c;
}