duanniedang3946 2016-05-02 00:54
浏览 69

Golang用于循环排列

I've been puzzling myself for around 5 hours now. I'm extremely new to Golang (2 day)...

I'm looking for a for loop that will create all permutations of a given sized string, using specific characters. Not only that, but it needs to be split into specific chunk sizes.. I'll try and visually show you what I need..

chars          := "abcdefghij"
string_size    := 6
blocks         := 5
start_position := 2

So the possibilities of this example would be 10 to the power of 6... so 1,000,000..

What I need is for this e.g. 1,000,000 to be split into 5 blocks mentioned above, so 200,000 guesses per for loop.

So specifying start position would lets say do something like

sections_usable := len(chars) / blocks
// sections_usable == 5
// this would then cherry pick 5 sections 
sections := make([]rune, blocks)
base_count := 0
for i := 0; i < blocks * sections_usable; i = i + sections_usable  {  
     sections[base_count] = rune(r[i])
     base_count++
}
for i, xi := range x {

    if i == 0 {

        // This is where its selecting the starting character
        // From the sections 
        p[i] = sections[block_to_use]

    } else {
        p[i] = r[xi]
    }

}

Heres an example of what data I'd want returned using

chars          := "abcdefghij"
string_size    := 6
blocks         := 5
start_position := 2

So start position 0 would be "a", 1 would be "c", 2 would be "e"

so using 0

aaaaaa

aaaaab

aaaaac

aaaaad

....

abbbbb

abbbbc

abbbbd

....

acdddd

acddde

acdddf

NOW USING start position 2

eaaaaa

eaaaab

eaaaac

...

And so on, but the permutations must stop before it starts the next block i.e

ejjjjj

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 想问一下stata17中这段代码哪里有问题呀
    • ¥15 flink cdc无法实时同步mysql数据
    • ¥100 有人会搭建GPT-J-6B框架吗?有偿
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决